使用自定义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 OKServer: Apache-Coyote/1.1Pragma: No-cacheCache-Control: no-cacheExpires: Thu, 01 Jan 1970 03:00:00 EETSet-Cookie: JSESSIONID=BB9D6783E58FB0F2ADE1924A2F0CBA52; Path=/Content-Type: text/html;charset=UTF-8Content-Length: 6233Date: Fri, 07 Sep 2012 14:41:13 GMT请求标头:OPTIONS /my-path HTTP/1.1Host: MY-HOME-NAMEUser-Agent: MY_USER_AGEMTAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip, deflateConnection: keep-aliveOrigin: HERE-GOES-DOMAINAccess-Control-Request-Method: POSTAccess-Control-Request-Headers: content-typePragma: no-cacheCache-Control: no-cacheCORS运作良好,所有必需的标头均由服务器发送,但如果按OPTIONS类型发送,则不能。是jQuery问题吗?jQuery-1.8.1
1 回答
- 1 回答
- 0 关注
- 559 浏览
添加回答
举报
0/150
提交
取消