.net 使用jQuery从ajax调用时从web服务获取响应的延迟
我正在使用jQuery调用一个web服务(c#)方法。从web服务获得结果后,我必须将数据绑定到html表单中。但问题是,在运行代码时,我从web服务得到的响应很晚,直到那时,我的函数返回null,并且没有设置表单字段。 下面是我的代码。这里我得到了v的空值.net 使用jQuery从ajax调用时从web服务获取响应的延迟,.net,web-services,jquery,.net,Web Services,Jquery,我正在使用jQuery调用一个web服务(c#)方法。从web服务获得结果后,我必须将数据绑定到html表单中。但问题是,在运行代码时,我从web服务得到的响应很晚,直到那时,我的函数返回null,并且没有设置表单字段。 下面是我的代码。这里我得到了v的空值 function CallBGHostService(aParam) { var v = null; $.ajax({ url: "http://localhost/MyService.asmx/GetBusinessGroup
function CallBGHostService(aParam) {
var v = null;
$.ajax({
url: "http://localhost/MyService.asmx/GetBusinessGroupData",
type: 'POST',
dataType: "json",
data: "{'aBusinessGroupID':'" + aParam + "'}",
contentType: "application/json; charset=utf-8",
beforeSend: function (xhr) { xhr.withCredentials = true; },
crossDomain: true,
success: function test(response) {
v = response.d;
alert(response.d);
},
error: function test(response) {
v = response.d;
alert(response.d);
}
});
return (v);
}
只需查看您在设置中收到的更改
数据类型:“text”
,并将success
函数更改为success:function(response){alert(response);},
。错误函数设置不正确,应该是:error:function(XMLHttpRequest,textStatus,errorwhold){alert(errorwhold);}
。此外,您不需要命名success
和error
函数。你当然不需要给他们起同样的名字 您能否尝试将数据:
更改为数据:{aBuisnessGroupID:aParam),
?@shaun5我更改了数据,但此服务无法运行。因为结果必须是json格式,所以我们无法更改数据类型。我还尝试更改成功和错误回调函数,但仍然无法从web服务获得延迟响应。延迟响应是什么意思?