2011-02-16 71 views
2

我有一个ajax查询,它调用WebService。它起作用并做它的事情,并且什么也没有返回(这是一个空白)。调试时应用程序中没有错误。但jquery .ajax的错误事件不断发射。 textStatus和errorThrown未定义。 XMLHttpRequest没有指示错误状态。从jQuery ajax到asp.net WebService的错误响应,但没有错误

为什么此查询认为它得到错误响应?另外奇怪的是:如果我在WebMethod中放置了断点,则在方法结束之前,将在客户端抛出错误。它似乎没有等待它完成,它只是正确的错误事件。我希望这事做这里的问题...

$.ajax({ 
     url: baseUrl() + "/webservices/usersetting.asmx/SetSetting", 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     async: true, 
     data: $.toJSON(ajaxData), 
     success: function (data) { 
      alert('success'); 
     }, 
     error: function (XMLHttpRequest, textStatus, errorThrown) { 
      alert("Error: " + errorThrown + " data: " + ajaxData.id); 
     } 
    }); 

当错误事件调试:

XMLHttpRequest 
abort: function(){w&&Function.prototype.call.call(g,w);L("abort")} 
onabort: null 
onerror: null 
onload: null 
onloadstart: null 
onprogress: null 
onreadystatechange: function(){} 
readyState: 4 
response: "" 
responseText: "" 
responseType: "" 
responseXML: null 
status: 0 
statusText: "" 
upload: XMLHttpRequestUpload 
withCredentials: false 
__proto__: XMLHttpRequest 

这里是方法。我用void return和“true”来试用它。尝试了响应格式Xml和Json。没有不同。

[WebMethod(EnableSession = true), 
ScriptMethod(ResponseFormat = ResponseFormat.Xml)] 
public string SetSetting(List<UserSettingData> data) 
{ 
    UserSettingManager setMgr = new UserSettingManager(Global.UserSession.UserID); 
    foreach (UserSettingData item in data) 
    { 
     setMgr.SetSetting(item.name, item.value); 
    } 

    return (jsonString(true)); 
} 
+0

这是一个跨域请求吗? – 2011-02-16 22:30:08

回答

0

问题在Visual Studio重新启动后解决。不知道为什么,但完成和完成。