我有一个通过将方法名称和数据作为参数进行 Asp.Net Web 服务调用的函数。将数据发送到服务没有问题。但我的回报值是undefined
function ServiceCommand(method, mdata) {
$.ajax({
url: "Service1.asmx/" + method,
type: "POST",
dataType: "json",
data: mdata,
contentType: "application/json; charset=utf-8",
success: function (msg) {
return msg;
},
error: function (e) {
return "error";
}
});
}
function Insert()
{
var Msg = ServiceCommand("HelloWorld", "{pwd:'1234',txt:'SomeText'}");
alert(Msg);// undefined
}
如何让 ServiceCommand 函数等到响应到来?我正在使用 JQuery 1.9(async:false
不起作用)我看到了一些建议使用的解决方案,$.When
但我无法弄清楚如何在这里使用。