我想使用jQuery.ajax()调用web服务,但不会调用webervice。 - 如果我更改url:引用.ashx文件,它会被调用,但不会被调用.asmx?
这是我正在使用的代码:
jQuery.ajax({
type: "POST",
url: "/services/CheckUsername.asmx/CheckUsername", // this doesn't get called
//url: "/services/CheckUsername.ashx/ProcessRequest", this gets called
data: '{ "context": "' + "username" + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Result: " + msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error: " + textStatus)
}
调用.ashx文件,但会重新调整parsererror,因为它返回了http上下文 - 我如何修改它以从Web服务获取字符串返回类型?
谢谢,
答案 0 :(得分:2)
尝试将[ScriptMethod]属性设置为服务器端方法
答案 1 :(得分:1)
我发现了如何将用户输入的用户名传递给HTTP处理程序。这是jQuery代码:
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");