【问题标题】:Internet Explorer treating AJAX GET request as POST request?Internet Explorer 将 AJAX GET 请求视为 POST 请求?
【发布时间】:2010-05-24 20:57:43
【问题描述】:

出于某种原因,只有在 IE(尝试过 7 和 8)中,jQuery 在应该是 GET 时才执行 POST 请求。见下文:

function(...) {
  /* ... */
  $.ajax({
    type: 'GET',
    dataType: 'script',
    url: '/something/' + id,
    processData: false,
    data: 'old_id=' + oldId,
    success:function(data) {
      alert(data);
    }
  });
  /* ... */
}

所有浏览器都能正确 GET,但 IE 正在执行 POST。为什么?

【问题讨论】:

  • 什么版本的 jQuery ?
  • 为什么使用'script'作为数据类型?

标签: jquery ajax internet-explorer post get


【解决方案1】:

这很可能是您之前使用该格式的请求的缓存问题,请将 cache:false 添加到 ajax 函数中,希望它应该没问题:

function(...) {
  /* ... */
  $.ajax({
    type: 'GET',
    cache:false, // this needed for IE
    dataType: 'script',
    url: '/something/' + id,
    processData: false,
    data: 'old_id=' + oldId,
    success:function(data) {
      alert(data);
    }
  });
  /* ... */
}

【讨论】:

    【解决方案2】:

    原来问题在于在调用$.ajaxSend() 时附加参数,这导致jQuery 库在IE 中将POST 请求转换为GET 请求。以下是有关我遇到的解决方案的更多信息:

    http://www.justinball.com/2009/07/08/jquery-ajax-get-in-firefox-post-in-internet-explorer/

    【讨论】:

      猜你喜欢
      • 2012-05-10
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 2014-05-12
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多