webservice doesn't get called by jQuery
I want to call a webservice using jQuery.ajax() but the webervice doesn't get called. - If I change the url: to reference a .ashx file it gets called but not .asmx?
Here's the code I'm using:
jQuery.ajax({
type: "POST",
url: "/services/CheckUsername.asmx/CheckUsername", // this doesn't get called
//url: "/services/CheckUsername.ashx/ProcessRequest", this gets called
data: '{ "con开发者_C百科text": "' + "username" + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Result: " + msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error: " + textStatus)
}
The .ashx file gets called but a parsererror is retuned because it's returning http context - how can I modify this to get a string return type from a webservice?
Thanks,
try setting [ScriptMethod] attribute to your server side method
I found out how to pass the username entered by the user to the HTTP handler. Here's the jQuery code:
jQuery.validator.addMethod("UsernameCheck", function (value, element) {
var allowed = true;
jQuery.ajax({
url: "/services/UsernameCheck.ashx",
global: false,
cache: false,
type: "get",
data: "profile_name=" + jQuery("#username").val(),
dataType: "text",
success: function (msg) {
if (msg == 1) {
allowed = true;
}
else {
allowed = false;
}
}
});
return allowed;
}, "Please enter a valid username");
精彩评论