Javascript 无法通过使用jquery传递参数来调用webservice
我使用jquery调用webservice,无论何时调用,都只得到错误结果。 我的服务器代码:Javascript 无法通过使用jquery传递参数来调用webservice,javascript,jquery,Javascript,Jquery,我使用jquery调用webservice,无论何时调用,都只得到错误结果。 我的服务器代码: [WebService(Namespace = "http://xxx.xample.org")] [WebServiceBinding( Name ="XService", Namespace="http://xxx.xample.org/XService.asmx?")] [System.Web.Script.Services.ScriptService] public class Aa
[WebService(Namespace = "http://xxx.xample.org")]
[WebServiceBinding( Name ="XService", Namespace="http://xxx.xample.org/XService.asmx?")]
[System.Web.Script.Services.ScriptService]
public class AathiService : System.Web.Services.WebService
{
[WebMethod]
public string IsValidUser(string UserName , string Password)
{
// process
return result;
}
}
}
然后我使用jquery调用服务,如下所示
$("#okButton").click(function () {
// CALLING WEBSERVICE
var param = { UserName: 'xxxx', Password: 'xxxxx' };
$.ajax({ type: "POST", contentType: "application/json;charset=utf-8", data: JSON.stringify(param),
url: "http://xxx.xample.org/xService.asmx/IsValidUser", dataType: "json", async: true,
success: function () { alert("success"); }, error: function (xhr,msg) { alert(msg + " " + xhr.responseText); }
});
});
我总是得到错误的部分。我不知道我做了什么。在您的webmethod中,您希望返回类型为“string”,但您使用数据类型JSON调用ajax调用 这将解决您的问题:
[WebMethod]
public JsonResult IsValidUser(string UserName , string Password)
{
// process
return Json(result);
}
只需更改async:false。问题已解决您是否正在尝试进行跨域调用?能否在函数上获得断点?7个月后。。。这是某种异步性