jQuery CORS内容类型选项

使用自定义Content-type的jQuery CORS发送AJAX正文请求时遇到问题。这是我的代码:


$.ajax({

  url: "http://some-other-domain/my-path",

  type: "POST",

  contentType: "application/json",

  dataType: "json",

  data: JSON.stringify({

    key: 1,

    key2: 2

  }),

  statusCode: {

    200: function(data) {

    }

  },

  xhrFields: {

    withCredentials: true

  },

  crossDomain: true

});

我需要将Content-type设置为“ application / json”,因为它需要服务器端。但是jQuery并非以POST形式发送请求,而是以OPTIONS形式发送请求。


这是标题:


响应标题:


HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Pragma: No-cache

Cache-Control: no-cache

Expires: Thu, 01 Jan 1970 03:00:00 EET

Set-Cookie: JSESSIONID=BB9D6783E58FB0F2ADE1924A2F0CBA52; Path=/

Content-Type: text/html;charset=UTF-8

Content-Length: 6233

Date: Fri, 07 Sep 2012 14:41:13 GMT

请求标头:


OPTIONS /my-path HTTP/1.1

Host: MY-HOME-NAME

User-Agent: MY_USER_AGEMT

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-us,en;q=0.5

Accept-Encoding: gzip, deflate

Connection: keep-alive

Origin: HERE-GOES-DOMAIN

Access-Control-Request-Method: POST

Access-Control-Request-Headers: content-type

Pragma: no-cache

Cache-Control: no-cache

CORS运作良好,所有必需的标头均由服务器发送,但如果按OPTIONS类型发送,则不能。是jQuery问题吗?


jQuery-1.8.1


largeQ
浏览 516回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JQuery