I am working on an internal web application at work. In IE10 the requests work fine, but in Chrome all the AJAX requests (which there are many) are sent using OPTIONS instead of whatever defined method I give it. Technically my requests are "cross domain." The site is served on localhost:6120 and the service I'm making AJAX requests to is on 57124. This closed jquery bug defines the issue, but not a real fix.

如何才能在Ajax请求中使用正确的http方法?

Edit:

这是在每页的文档加载中:

jQuery.support.cors = true;

And every AJAX is built similarly:

var url = 'http://localhost:57124/My/Rest/Call';
$.ajax({
    url: url,
    dataType: "json",
    data: json,
    async: true,
    cache: false,
    timeout: 30000,
    headers: { "x-li-format": "json", "X-UserName": userName },
    success: function (data) {
        // my success stuff
    },
    error: function (request, status, error) {
        // my error stuff
    },
    type: "POST"
});

推荐答案

Chrome正在对查找CORS个标题的请求进行印前判断.如果请求是可接受的,则它将发送真正的请求.如果您是跨域执行此操作,则只需处理它,或者找到使请求非跨域的方法.这就是jQuery错误被关闭为无法修复的原因.这是设计好的.

与简单的请求不同(上面讨论过),"预飞"请求优先

  • 它使用的方法不是GET、HEAD或POST.此外,如果POST用于发送内容类型不同于
  • 它在请求中设置自定义标头(例如,请求使用X-PINGOTHER之类的标头)

Jquery相关问答推荐

使用 shell 脚本判断 json 数组响应是否具有特定用户名和状态的 jq 命令

jQuery在localStorage时将类添加到正文

Flask,如何为ajax调用返回成功状态码

Ajax 替换而不是追加

通过 .push() 方法向对象添加项目

如何制作 AngularJS 指令来停止传播?

jQuery Mobile:动态添加内容的标记增强

JQUERY UI Accordion 开始折叠

使用 jQuery 刷新(重新加载)页面一次?

隐藏 div 但保留空白

Javascript 将 Markdown/Textile 转换为 HTML(理想情况下,返回 Markdown/Textile)

如何从 jQuery UI datepicker 获取日期

如何让 JavaScript/jQuery Intellisense 在 Visual Studio 2008 中工作?

将片段添加到 URL 而不导致重定向?

通过单击按钮获取表格行的内容

带有回调ajax json的jQuery自动完成

删除除一个之外的所有类

IE8 和 JQuery 的 trim()

Twitter Bootstrap alert 消息关闭并再次打开

我应该在addClass之前使用hasClass吗?