我正在使用jQuery 1.10.1。我想发送内容类型设置为application/json的POST请求。我做了以下内容:jQuery不发送内容类型为application/json的发布请求
$.ajax({
type: "post",
url: urlBase + "user/search",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(filter),
success: renderResponse,
error: function(error) {
console.log(error)
}
})
但POST不发送,并且我得到错误回调以下回应:
对象{readyState的= 0,状态= 0,状态文本=”错误“}
生成OPTIONS请求,但是没有POST。这里是选项的要求和回应:
Antwort-Header
Access-Control-Allow-Head... X-Requested-With
Access-Control-Allow-Meth... GET, POST, OPTIONS
Access-Control-Allow-Orig... *
Access-Control-Max-Age 86400
Allow GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
Content-Length 0
Server Jetty(6.1.1)
Anfrage-Header
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Access-Control-Request-He... content-type
Access-Control-Request-Me... POST
Cache-Control no-cache
Connection keep-alive
Host localhost:8080
Origin http://localhost
Pragma no-cache
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0
这里有什么问题?我如何让jQuery设置我想要的内容类型标题?
什么是过滤器?浏览器控制台 –
中的任何东西都只是一个JSON内容,它简直就是{} –
此链接也可以帮助您:http://stackoverflow.com/questions/5596341/jquery-ajax-post-does-not-send-数据到Web服务器 – kmas