2012-09-19 50 views
0

我正在通过jQuery ajax向.NET通用处理程序(.ashx)发出请求。jQuery ajax请求只能同步工作,不会在异步时返回

我正在返回JSON,我已经在JSONLint上进行了验证,但无法发布,因为它是敏感数据。

问题是调用只在同步完成时返回(async:false)。当异步完成时,它永远不会回来。 async:false将调用我的成功功能以及所有全局功能。 async:true将只调用全局函数ajaxStartajaxSend,async:false将调用这些以及其他。

我不知道如何进一步调试或确定为什么没有响应回来。

$.ajax({ 
    type: "POST", 
    async: false, 
    cache: false, 
    timout: 600000, 
    data: request_object.GetQueryString(), 
    dataType: "json", 
    responseType: "json", 
    error: function (request, error_type, error_message) { 
     alert("error"); 
    }, 
    success: function (data, status, request) { 
     alert("success"); 
    }, 
    url: "./ReportRequestHandler.ashx", 
    complete: function() { 
     alert("here"); 
    } 
}); 

$(document).ajaxError(function() { 
    alert("ajaxError"); 
}).ajaxSend(function() { 
    alert("ajaxSend"); 
}).ajaxStart(function() { 
    alert("ajaxStart"); 
}).ajaxStop(function() { 
    alert("ajaxStop"); 
}).ajaxSuccess(function() { 
    alert("ajaxSuccess"); 
}).ajaxComplete(function() { 
    alert("ajaxComplete"); 
}); 
+0

超时时出现拼写错误..也。检查网络面板的萤火虫或在控制台的铬为xhr请求,以便您可以知道是什么问题 –

回答

0

我认为它是因为“。”在URL中。你尝试删除它吗?检查这个问题,以及它们具有类似的

jQuery not getting reply when using asynchronous

希望它可以帮助

+0

我使用的按钮是在异步请求期间提交页面,当然同步是保持足够长的时间响应。页面非常短,以至于快速查看页面。 –

0

我跑的代码与你的配置SANS异步属性的页面,似乎是为我工作的罚款东西..

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Pages" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 

    <title></title> 

    <script type="text/javascript"> 
     $(document).ajaxError(function() { 
      alert("ajaxError"); 
     }).ajaxSend(function() { 
      alert("ajaxSend"); 
     }).ajaxStart(function() { 
      alert("ajaxStart"); 
     }).ajaxStop(function() { 
      alert("ajaxStop"); 
     }).ajaxSuccess(function() { 
      alert("ajaxSuccess"); 
     }).ajaxComplete(function() { 
      alert("ajaxComplete"); 
     }); 
     $.ajax({ 
      type: "POST", 
      timout: 600000, 
      data: { 'type': 'check' }, 
      dataType: "json", 
      responseType: "json", 
      error: function(request, error_type, error_message) { 
       alert("error"); 
      }, 
      success: function(data, status, request) { 
       alert("success"); 
      }, 
      url: "../../Ajax/GenericData.ashx", 
      complete: function() { 
       alert("here"); 
      } 
     }); 

    </script> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    </div> 
    </form> 
</body> 
</html> 

我得到了当异步都是为了警告消息..你能检查浏览器的控制台部分,看看怎么回事就正好与你的要求:假的,从您的配置中删除..

+0

在.ashx中放置一个调试点,并在两种类型的请求都开始时查看该点是否被命中 –

0

我发现了这个问题。 用于触发事件的按钮提交页面并重新加载速度太快,以至于看不到任何闪烁。