【问题标题】:jQuery.Ajax not working in Chome, but it is in IEjQuery.Ajax 在 Chrome 中不起作用,但在 IE 中
【发布时间】:2015-03-06 18:39:02
【问题描述】:

我有一些 ajax 在 Chrome 中导致问题,但在 IE 中没有。我使用 Fiddler 捕获流量并将其与 IE 流量进行比较,我发现 Chrome 请求中缺少内容类型,并且 chrome 请求中的动词设置为“选项”而不是发布。当我修改这两件事并使用 Fiddler 重新提交时,它工作正常。任何想法是什么导致了这些问题?

jQuery.ajax({ 
   url: url,
   type:'POST',
   contentType:"application/json; charset=utf-8",
   cache: false,
   data: request, 
   success:function(data) { 
      alert("Success!!!"); 
   }, 
   error: function(jqxhr, textStatus, errorThrown){ 
      alert("Error : " + errorThrown + " textStatus: " + textStatus );
   } 
});

【问题讨论】:

  • @Patrick,谢谢,这有助于给我一个更好的错误信息。问题没有解决。错误消息指出“网络错误:无法在 XmlHttpRequest 上执行‘发送’”。当我处理 Json 时,它在谈论 XmlHttpRequest 是什么?
  • 使用 dataType: 'json' 代替 contentType

标签: jquery ajax


【解决方案1】:

这是我在项目中使用的 ajax 的结构,它在 IE 和 Chrome 中完美运行,

$.ajax({
            url: 'api/Test/GetData',
            type: 'POST',
            dataType: 'json',
            data: SearchRequest,
            success: function (data, textStatus, xhr) {

            },
            error: function (xhr, textStatus, errorThrown) {
            }
      });

不同的是,我使用 dataType: 'json' 而不是 contentType。

【讨论】:

    猜你喜欢
    • 2015-03-31
    • 2017-10-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-03
    • 1970-01-01
    相关资源
    最近更新 更多