2011-10-10 77 views
2

我有以下Web服务;从jQuery调用Web服务会返回“无传输”错误

[WebMethod] 
public string HelloWorld() 
{ 
    return "Hello World"; 
} 

我指向最新的jQuery库。

<script type="text/JavaScript" src="Scripts/jquery-1.6.4.js"></script> 

我有这个jQuery方法;

$.ajax({ 
      type: "POST", 
      url: "../Service/AFARService.asmx/HelloWorld", 
      // this._baseURL + method, 
      data: data, 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: fnSuccess, 
      error: fnError, 
      crossDomain: true, 
      dataFilter: function (data) { 
       var response; 

       if (typeof (JSON) !== "undefined" && typeof (JSON.parse) === "function") 
        response = JSON.parse(data); 
       else 
        response = val("(" + data + ")"); 

       if (response.hasOwnProperty("d")) 
        return response.d; 
       else 
        return response; 
      } 
     }); 

当我执行我得到一个“没有交通”错误返回。我补充说crossDomain: true仍然没有成功。

在此先感谢 BB

+0

尝试用'类型: “GET”' – Rafay

+0

也同样的错误与 “GET”。 – BumbleBee

+0

您的服务器“Hello World”的响应是无效的JSON! – Eric

回答

0

尝试使用

url: "AFARService.asmx/HelloWorld", 



[WebMethod] 
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] 
public string HelloWorld() 
{ 
    return "Hello World"; 
}