Reputation: 285
I can't see the problem in working of this simple code
setdata.asmx
[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 setdata : System.Web.Services.WebService {
public setdata () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
}
my jquery
$.ajax({
method: "POST",
url: "setdata.asmx/HelloWorld",
contentType: "text/plain; charset=utf-8",
//data: { category: category },
success: function (txt) {
alert(txt);
},
error: function(jqXHR, textStatus, errorThrown ){
alert("Error:"+jqXHR + textStatus + errorThrown);
}
});
the error is:
[object Object]errorInternal Server Error
how can i resolve it
I made a guess of the problem:-
The jquery is inside the default.aspx page in admin folder of my website named web1
and i am posting the url simply setdata.asmx ,
does the server look for setdata.asmx in current directory of root directory
Upvotes: 1
Views: 1443
Reputation: 4628
Try updating the jQuery script to check the error:
$.ajax({
method: "POST",
url: "<%= this.ResolveUrl("~/setdata.asmx")%>/HelloWorld",
contentType: "text/plain; charset=utf-8",
//data: { category: category },
success: function (txt) {
alert(txt);
},
error: function (jqXHR, textStatus, errorThrown) {
alert("Error:" + jqXHR + textStatus + errorThrown);
}
});
This should simplify debugging.
Aldo use the ResolveUrl
method to get the correct address for the service.
Upvotes: 1
Reputation: 2895
Please make sure you've added necessary web.config entries to call asmx service from client script. Check below URL:
http://encosia.com/asmx-scriptservice-mistakes-installation-and-configuration/
Upvotes: 0