Can you help me to find out why my $.ajax call to HelloWorld webservice fails here?
I am trying my best but cannot figure out why I do not get a sucesful response to such a simple web service; can you have a look at it tell me what do I miss, pls?
Each time only the error function is called and Fiddler says I have HTTP Response 500.
thanks!
Additional Notes: I checked Fiddler and it says: No web service found at: /JQuery-Recepie/Chapter16-Ajax/MyWebService.asmx. But WHY?!?
My WebService class:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyWebService : System.Web.Services.WebService {
public MyWebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}
My JavaScript that is bound to a b开发者_开发知识库utton's click event which calls the webservice:
function jqHelloCall(){
$.ajax({ type: "POST",
contentType: "application/json; charset=utf-8",
url: "MyWebService.asmx/HelloWorld",
data: "{}",
dataType: "json",
success: function(msg){
alert(msg==null);
alert(msg.d);
},
error: function(){
alert('error');
}
}); }
Use the Firebug in Firefox to see the response sent by IIS. In Firebug on the Net tab you can filter only the Ajax requests (XHR). Most certainly you will find all the details about server exception in the response body IIS will send back.
pencilCake : I checked Fiddler and it says: No web service found at: /JQuery-Recepie/Chapter16-Ajax/MyWebService.asmx. But WHY?!?
Because the web methods should be STATIC
[WebMethod]
public static string HelloWorld() {
return "Hello World";
}
add the scriptMethod attribute to your service method...
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld() {
return "Hello World";
}
精彩评论