How to call webservice through jquery... I tried following code..
$(document).ready(function() {
$("#sayHelloButton").click(function(event){
$.ajax({
type: "POST",
url: "C:/Webservice/Service.asmx/HelloToYou",
data: "{'name': '" + $('#name').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: functio开发者_如何转开发n(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
My doubt is where my web service should be? Whether I need to publish it and use that path or the service should be within the same solution..
Plz, Clear my doubt
You need to make sure the URL is on the same server as the HTML page. There are various ways to specify the URL without explicitly writing out the hostname, such as:
url: "/Webservice/Service.asmx/HelloToYou",
C:/ is definitely incorrect, though.
精彩评论