jquery - $.ajax 中的某些参数未传递

标签 jquery ajax json authorization

我有这个功能

$.ajax({
    url: aurl,
    method: 'GET',
    beforeSend: function (req) { req.setRequestHeader('Authorization', auth); },
    cache: false,
    dataType: "json",
    error: function () {
        //error code
    },
    success: function (t) {
        //success code
    }
});

但是,参数:

  • 方法
  • 发送前
  • 缓存

被我的浏览器 FF3、IE8 和 Chrome 忽略。因此,无论放置在那里,都不会更改浏览器发送到给定 url 的请求,例如:无法将方法设置为“POST”,或者更重要的是,不能将任何授权参数作为请求的一部分放置,以便 HTTP 授权表单已处理。

另一个奇怪的行为是除非 数据类型:“json” 将不会发送或接收任何请求或响应,如使用 FF3 中的 LiveHTTPHeaders 所示。例如,如果数据类型:“xml”。

浏览器似乎正确处理了 URL。

遇到这些问题的人如何确保发送这些额外参数?

最佳答案

URL 是远程的还是本地的?

根据JQuery Documentation

Note: All remote (not on the same domain) requests should be specified as GET when 'script' or 'jsonp' is the dataType (because it loads script using a DOM script tag). Ajax options that require an XMLHttpRequest object are not available for these requests. The complete and success functions are called on completion, but do not receive an XHR object; the beforeSend and dataFilter functions are not called.

以及cache选项,默认值为:“dataType ' script ' 和 ' jsonp ' 为 false”

关于jquery - $.ajax 中的某些参数未传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/724920/

相关文章:

javascript - 如何同时滚动 iframe 和父页面?

javascript - Adobe Edge - 从 html 页面控制动画

ajax - 来自 Yii CListView 的 "Post"参数

java - 是否有 java 11 native 方法将 json 转换为对象?

javascript合并两个函数以检查另一个元素的节点类型

javascript - 使用 Javascript 连接字符串以组合新的 DOM 元素时,它只采用第一个空格分隔值

javascript - Click 事件不适用于 Ajax 加载的内容

php - 在数据库中插入新数据时警告用户

javascript - D3 V4 TreeMap 报错“Uncaught Error : missing: Comedy-Musical

python - 将 python 输出格式化为 json