我正在使用jQuery 1.10.1。我想发送内容类型设置为 application/json 的 POST 请求。我正在执行以下操作:
$.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, status=0, statusText="error"}
生成了 OPTIONS 请求,但没有 POST 跟随。以下是 OPTIONS 请求和响应:
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 设置我想要的内容类型标题?