简体   繁体   English

在IE中获取json数据有效,但FF和Chrome无效

[英]Getting json data works in IE but not FF and Chrome

It seems one of the JSON requests in my mvc app fails when using Firefox but works on IE (and this part seems to work in chrome as well). 看来,使用Firefox时,我的mvc应用程序中的JSON请求之一失败了,但可以在IE上使用(这部分似乎也可以在chrome中使用)。 I thought it might be due to the same-origin policy, but according to my understanding it shouldn't cause any trouble, as all requests use the same host and protocol (in this situation, localhost). 我认为这可能是由于同源策略引起的,但是据我了解,这不会造成任何麻烦,因为所有请求都使用相同的主机和协议(在这种情况下为localhost)。 When i checked the requests in the net functions of firefox, ie and chrome debuggers, it seems the request made by IE and Chrome is answered with 270b, while the FF request gets only 2b. 当我在firefox(即chrome调试器)的网络功能中检查请求时,似乎IE和Chrome发出的请求得到了270b的答复,而FF请求仅得到了2b。 Any help would be appreciated. 任何帮助,将不胜感激。

Code: 码:

$(function () {
    // this seems to work fine in FF and IE
    var IncludeTerminatedFlag = getIncludeTerminatedFlag();
    $.getJSON("/Search/GetDebtorList", { DebtorNameCode: '', CountryCode: CountryCode, IncludeTerminatedFlag: IncludeTerminatedFlag }, function (data) {
       // some actions
    });
    // this works fine in FF and IE
    $.getJSON("/Search/GetStaffList", { StaffNameCode: '', CountryCode: CountryCode, IncludeTerminatedFlag: IncludeTerminatedFlag }, function (data) {
        // some actions
    });
    // this works fine in FF and IE
    $.getJSON("/Search/GetStaffList", { StaffNameCode: '', CountryCode: CountryCode, IncludeTerminatedFlag: IncludeTerminatedFlag }, function (data) {
       // some actions
    });

    // this does not work in FF but works in IE
    $.getJSON("/Search/GetClientList", { ClientNameCode: '', CountryCode: CountryCode, IncludeTerminatedFlag: IncludeTerminatedFlag }, function (data) {
      // some actions
    });

}

EDIT: When i tried to debug it under firefox, it seems the laston getJSON call fails? 编辑:当我尝试在firefox下调试它时,似乎laston getJSON调用失败了? as in it does not go inside the funcion. 因为它不会进入功能。 It also does not work when I try the $ajax syntax 当我尝试$ ajax语法时,它也不起作用

The JSON being returned could be not properly formatted(Chrome is very strict). 返回的JSON格式可能不正确(Chrome非常严格)。 Try adding error catching to see what the error is in Chrome 尝试添加错误捕获以查看Chrome中的错误是什么

$.getJSON("/Search/GetDebtorList", { DebtorNameCode: '', CountryCode: CountryCode, IncludeTerminatedFlag: IncludeTerminatedFlag }, function (data) {
   // some actions
})
.error(function(data) {
  console.log("Error: " + data);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM