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.

我正在工作的一个内部web应用程序。在IE10中,请求工作得很好,但是在Chrome中,所有AJAX请求(有很多)都是使用选项发送的,而不是我给出的任何定义的方法。从技术上来说,我的请求是“跨领域的”。该站点是在本地主机上服务的:6120,而我正在发出AJAX请求的服务是在57124。这个封闭的jquery bug定义了这个问题,但不是真正的解决方案。

What can I do to use the proper http method in ajax requests?

在ajax请求中,如何使用适当的http方法?

Edit:

编辑:

This is in the document load of every page:

这是在每一页的文件装载:

jQuery.support.cors = true;

And every AJAX is built similarly:

每一个AJAX都是类似的:

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"
});

8 个解决方案

#1


99

Chrome is preflighting the request to look for CORS headers. If the request is acceptable, it will then send the real request. If you're doing this cross-domain, you will simply have to deal with it or else find a way to make the request non-cross-domain. This is why the jQuery bug was closed as won't-fix. This is by design.

Chrome是预置的,要求搜索CORS头文件。如果请求是可接受的,那么它将发送真正的请求。如果您正在执行这个跨域,您将只需要处理它,或者找到一种方法来实现请求的非跨域。这就是为什么jQuery bug被关闭的原因。这是通过设计。

Unlike simple requests (discussed above), "preflighted" requests first send an HTTP request by the OPTIONS method to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a request is preflighted if:

与简单的请求(上面讨论的)不同,“预先设置”请求首先通过选项方法向另一个域中的资源发送一个HTTP请求,以确定实际请求是否安全。跨站点请求是这样的,因为它们可能对用户数据有影响。特别地,如果:

  • It uses methods other than GET, HEAD or POST. Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted.
  • 它使用的方法除了GET、HEAD或POST。此外,如果POST用于发送请求数据,而不是应用程序/x-www-form-urlencode、多部件/表单数据或文本/plain,例如,如果POST请求使用应用程序/ XML或文本/ XML向服务器发送一个XML有效负载,则该请求将被预先设置。
  • It sets custom headers in the request (e.g. the request uses a header such as X-PINGOTHER)
  • 它在请求中设置自定义标头(例如,请求使用一个头,例如X-PINGOTHER)

更多相关文章

  1. 如何使用ajax GET或POST方法将数据传递到amazon lambda节点。js
  2. Jquery常用技巧和方法收集
  3. Chosen 基于jquery的选择框插件使用方法
  4. jQuery $ajax 传中文数据到action乱码解决方法
  5. JQuery 的选取元素 和 方法
  6. jquery的function方法中each循环里面判断失败跳出function方法
  7. js/jquery常用方法------复制粘贴至剪切板
  8. Jquery ready和window.onload方法区别
  9. jQuery -> 获取后代元素的三种方法

随机推荐

  1. 以编程方式编写CSS背景的最佳方法?
  2. 安装nginx并配置php环境
  3. 在Yii中获取当前控制器和操作ID
  4. 基于PHP聊天室的编程思想
  5. 检查PHP是否启用了JavaScript
  6. php计算几分钟前、几小时前、几天前的几
  7. jQuery ajax调用不会调用我的php页面
  8. 复制到剪贴板没有瑞士法郎。只使用javasc
  9. 使用codeigniter发布到wordpress.com博客
  10. 用简单的馅饼从原子进料中拉出