在镀铬jQuery的阿贾克斯问题 [英] jquery ajax problem in chrome

查看:119
本文介绍了在镀铬jQuery的阿贾克斯问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网页就好在FF和IE浏览器运行以下的jQuery code,但镀铬似乎吓坏了。

在FF和IE浏览器的调用时,结果被追加到div。 在镀铬,它调用ajaxfailed失败。

传递给AjaxFailed函数XMLHtt prequest具有200状态code和状态文本是OK。在readyState为4和responseText的设置为我想从我可以看到它的调用失败的方法追加到div ..基本数据,但它不是失败..我曾尝试与GET和POST请求,它老是打断镶边。

 函数getBranchDetails(的ContactID,branchID){
  $阿贾克斯({
    键入:GET,
    网址:urlToRequestTo,
    数据: {},
    的contentType:应用/ JSON的;字符集= UTF-8,
    数据类型:JSON,
    成功:branchDetailsS​​uccess,
    错误:AjaxFailed
  });
}



 功能branchDetailsS​​uccess(结果){
      $(#divBranchControl)空()。
      $(#divBranchControl)追加(+结果)。
      $(#branchDiv)的选项卡()。
    }



 功能AjaxFailed(结果){
      警报(失败:+ result.status +''+ result.statusText);
    }
 

解决方案

我刚才看到,这个问题已经得到了很多意见,其仍处于打开状态。我都忘了这件事完全和希望这将让我关闭它。

数据类型参数设置为无,甚至删除的数据类型的参数完全可以解决这个问题。

在我的例子中,我返回渲染视图(字符串的HTML代码段),并在此code我指定的数据类型为JSON的时候,确实是不。大多数其他浏览器似乎忽略了数据类型,如果它不正确,并与生活继续前进,让我追加HTML结果。

Chrome浏览器会引发错误。 状态文本正常,状态code是200,因为实际的Ajax请求通过罚款去了。这个问题无关的请求本身,问题是,返回的数据是不是我说的镀铬的那样。

所以,镀铬休息。 如果我完全删除数据类型参数的镀铬数字出来的数据是什么时候得到它。如果我设置了数据类型参数设置为HTML,那么它​​也能正常工作。

长话短说,这个问题是不是镀铬。是我。因为我很愚蠢这样。我标志着以此为回答这个问题,因为它回答psented在原来问题的例子,我$ P $。

在评论其他人描述的其他情况下,这种解决方案是最有可能没有什么帮助。

i have the following jquery code running on my page just fine in FF and IE, but chrome seems to be freaking out..

in FF and IE the call is made and the result is appended to the div. in chrome, it calls ajaxfailed on failure.

the XMLHttpRequest passed to the AjaxFailed function has a status code of "200" and the statusText is "ok". the readystate is 4 and the responseText is set to the data i wish to append to the div.. basically from what i can see its calling the failure method but it isn't failing.. i have tried with both get and post requests and it always breaks in chrome.

function getBranchDetails(contactID, branchID) {
  $.ajax({
    type: "GET",
    url: urlToRequestTo,
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: branchDetailsSuccess,
    error: AjaxFailed
  });
}



 function branchDetailsSuccess(result) {
      $("#divBranchControl").empty();
      $("#divBranchControl").append(" " + result);
      $("#branchDiv").tabs();
    }



 function AjaxFailed(result) {
      alert("FAILED : " + result.status + ' ' + result.statusText);
    }

解决方案

I just saw that this question has gotten a lot of views, and its still open. I'd forgotten about it completely and hopefully this will let me close it.

Setting the datatype argument to nothing, or even removing the datatype argument completely will solve the problem.

In my example I am returning a rendered view (an html snippet in string) and in this code I'm specifying the data type to json, when really it isn't. Most other browsers seem to ignore the datatype if its incorrect and move on with life, allowing me to append the html result.

Chrome throws an error. The status text is OK, the status code is 200, because the actual ajax request went through fine. The problem has nothing to do with the request itself, the problem is that the data returned is not what I told chrome it would be.

So chrome breaks. If I remove the datatype argument completely chrome figures out what the data is when it gets it. If I set the datatype argument to "html" then it also works fine.

Long story short, the problem is not chrome. Its me. Because I'm dumb like that. I am marking this as the answer to this question as it answers the example I presented in the original question.

In the comments others have described other situations where this solution is most likely not going to help.

这篇关于在镀铬jQuery的阿贾克斯问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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