jQuery的阿贾克斯停止不调用(无误差; 200 OK) [英] jQuery Ajax Stop is not invoked (No error; 200 OK)

查看:110
本文介绍了jQuery的阿贾克斯停止不调用(无误差; 200 OK)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作ASP.Net 2.0 $ C $在我的开发服务器C,它使用jQuery阿贾克斯。 Ajax调用的结果用于加载下拉列表值。

I have a working ASP.Net 2.0 code in my development server that uses jQuery Ajax. The result of the ajax call is used to load dropdown values.

但是,当这code被部署到一个新的DMZ主机,结果没有得到填充在下拉 - 尽管我得到 200 OK 作为回应。一个显而易见的是,键入是在响应不同。预计为应用程序/ JSON 但未来为文本/纯

But when this code is deployed to a new DMZ server, the result is not getting populated in dropdown – though I am getting 200 OK as response. One obvious thing is that the Type is different in the response. It is expected as application/json but coming as text/plain.

我有成功回调和错误回调codeS。伴随着这一点,我对AJAX的处理程序启动和停止。但是,这些事件会被解雇。什么是错误 / 停止处理程序不被解雇的原因是什么?我们怎样才能使它工作?

I have success call back and error callback codes. Along with this I have handlers for ajax start and stop. But none of these events are getting fired. What is the reason error/stop handlers are not getting fired? How can we make it work?

注:该行为是在IE和Chrome相同

Note: The behavior is same in both IE and Chrome.

更新

另外观察到,有记录在控制台的误差,如下所示。这是否与在键入?我们如何解决这个问题?

Also observed that there is an error logged in console, as shown below. Is it related to the "Type"? How can we address this?

请注意:还要注意的是的Content-Length 是在下面所示的响应头0

Note: Also note that the Content-Length is 0 in the response headers shown below.

成功回调

的jQuery

      function loadASN()
      {
            var receiveScanParameter = getContainerParameters();

           // console.log(receiveScanParameter);

            $.ajax({
                    type: "POST",
                    url: "rcvScanTXAdd.aspx/GetASNForPlant",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: JSON.stringify({ receiveScanParameter: receiveScanParameter }),
                    success: successPopulateASN,
                    error: errorFunction
                    });
      }

全球的jQuery code

    //Global Ajax Error handling Function
    function errorFunction(xhr, status, error) 
    {
              if(xhr == 'undefined' || xhr == undefined)
              {
                alert('xhr undefined');
              }

              alert(status);
              alert(error);
    }


 $(document).ready(function () 
 {
    //Ajax Start
    $('body').ajaxStart(function() 
    {
        //Change cursor to waiting 
        $(this).css({'cursor':'wait'})
    });

    //Ajax End
    $('body').ajaxStop(function() {

        //Reset the cursor
        $(this).css({'cursor':'default'})

    }); 



 });

屏幕截图

推荐答案

我想通了。

第1步:观察有(话说结果为空)登录浏览器的控制台错误。 [这个截图中的问题更新]

Step 1: Observed that there is an error logged in browser’s console (saying result is null). [This screenshot is updated in the question]

第2步:观察发现的内容长度的响应是零。还观察到,有一个的gzip COM pression发生的响应(通过读取响应头)。

Step 2: Observed that the content length of the response is zero. Also observed that there is a gzip compression happened on the response (by reading the response headers).

第3步:分析服务器的web.config。它是一个uisng C# HTTP模块 COM pression 。在HTTP模块添加绕过逻辑 JSON 。 [我不想JSON是COM pressed这个自定义模块。后来,我将考虑增加COM pression以JSON当我使用 IIS 为COM pression,而不是自定义模块。以下是绕过JSON COM pression

Step 3: Analyzed the server's web.config. It was uisng a C# httpModule for compression. In that httpModule added bypassing logic for json. [I don’t want json to be compressed with this custom module. Later I will consider adding compression to JSON when I use IIS for compression instead of custom module]. Following is the C# code segment for by-passing JSON compression

request.ContentType.ToLower(CultureInfo.InvariantCulture).StartsWith("application/json")

这篇关于jQuery的阿贾克斯停止不调用(无误差; 200 OK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆