我正在使用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