大佬教程收集整理的这篇文章主要介绍了jQuery ajax调用是否支持PATCH?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
该$.AJAX
方法 确实 支持http PATCH。
您看到的问题是该AJAX
方法Access-Control-Allow-
Methods
在选项预检检查的响应标头中查找PATCH
。您的响应中缺少此标头,或者此标头的值中未包含PATCH方法。无论哪种情况,问题都出在服务器上,而不是客户端代码中。
这是使用Java的示例:
response.addheader("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, deletE");
当我发送此ajax rquest时:
$.ajax({
headers : {
'Accept' : 'application/json','Content-Type' : 'application/json'
},url : 'http://localhost:8080/wutup/venues/12',type : 'PATCH',data : JSON.Stringify({description: "842490812321309213801923 gonzagazors"}),success : function(response,textStatus,jqXhr) {
console.log("Venue successfully Patched!");
},error : function(jqXHR,errorThrown) {
// log the error to the console
console.log("The following error occured: " + textStatus,errorThrown);
},complete : function() {
console.log("Venue Patch Ran");
}
});
我收到此错误:
XMLhttprequest无法加载http://:// localhost:8080 / wutup / venues / 12。Access-
Control-Allow-Methods不允许使用方法PATCH。
但是,使用curl:
$ curl -v -H "Accept: application/json" -H "Content-type: application/json" -X PATCH - d' {"address": "8421 Gonzaga Ave"}' http://localhost:8080/wutup/venues/12
About to connect() to localhost port 8080 (#0)
Trying 127.0.0.1... connected
Connected to localhost (127.0.0.1) port 8080 (#0)
PATCH /wutup/venues/12 http/1.1
User-Agent: curl/7.21.1 (i686-pc-mingw32) libcurl/7.21.1 OpenSSL/0.9.8r zlib/1.2.3
Host: localhost:8080
Accept: application/json
Content-type: application/json
Content-Length: 57
http/1.1 204 No Content
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: *
Date: Fri,30 Nov 2012 08:14:35 GMT
Connection #0 to host localhost left intact
Closing connection #0
以上是大佬教程为你收集整理的jQuery ajax调用是否支持PATCH?全部内容,希望文章能够帮你解决jQuery ajax调用是否支持PATCH?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。