【问题标题】:Delay in getting response from web service while calling from ajax using jQuery使用 jQuery 从 ajax 调用时延迟从 Web 服务获取响应
【发布时间】:2012-04-11 12:00:26
【问题描述】:

我正在使用 jQuery 调用 Web 服务 (c#) 方法。从 Web 服务获取结果后,我必须以 html 形式绑定数据。但问题是,在运行代码时,我从 Web 服务得到延迟响应,直到那时我的函数返回 null 并且没有设置表单字段。 下面是我的代码。在这里,我得到 v 的 null 值

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);

}

【问题讨论】:

  • 您可以尝试将您的data: 更改为data: { aBuisnessGroupID: aParam), 吗?
  • @shaun5 我更改了数据,但随后此服务无法正常工作。

标签: .net web-services jquery


【解决方案1】:

只是为了查看您在设置中收到的更改dataType: "text" 并将您的success 函数更改为success: function(response) {alert(response);},。您的错误函数设置不正确,它应该是:error: function(XMLHttpRequest, textStatus, errorThrown){alert(errorThrown);}。此外,您不需要命名 successerror 函数。您当然不需要将它们命名为相同的东西!

【讨论】:

  • 由于结果必须是 json 格式,所以我们无法更改数据类型。另外我尝试更改成功和错误回调函数,但没有运气仍然得到来自网络服务的延迟响应
  • 延迟响应是什么意思?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-26
相关资源
最近更新 更多