我正在嘗試使用我的同事開發的演示webservices進行身份驗證。 如果我嘗試從Chrome中的高級休息客戶端插件調用,則允許跨源資源共享並且完美工作。 但是當我嘗試使用代碼訪問,我得到500服務器錯誤JQuery Ajax對RESTfull API的錯誤請求
.ajax({
type : "POST",
dataType: 'json',
url: 'CANTPOSTTHISURL/rest/session',
contentType: "application/json; charset=utf-8",
data: JSON.stringify({"username": "admin", "password": "admin" }),
success: function(response)
{
console.log(response);
},
error: function (data, status) {
console.log('Sample of error data:', status);
console.log("readyState: "+data.readyState+"\nstatus: "+data.status+"\nresponseText: "+data.responseText);
},
complete: function(xhr, status) {
console.log('COMPLETE');
}
});
的我得到的錯誤是:
OPTIONS CANTPOSTTHISURL/rest/session 500 (Internal Server Error) jquery.js:8475
send jquery.js:8475
jQuery.extend.ajax jquery.js:7930
authenticate wts.js:5
(anonymous function) wts.js:27
jQuery.event.dispatch jquery.js:3045
elemData.handle jquery.js:2721
jQuery.event.trigger jquery.js:2957
(anonymous function) jquery.js:3639
jQuery.extend.each jquery.js:631
jQuery.fn.jQuery.each jquery.js:253
jQuery.fn.extend.trigger jquery.js:3638
H jquery.mobile-1.3.0.min.js:2
I jquery.mobile-1.3.0.min.js:2
jQuery.event.dispatch jquery.js:3045
elemData.handle jquery.js:2721
OPTIONS CANTPOSTTHISURL/rest/session Invalid HTTP status code 500 jquery.js:8475
send jquery.js:8475
jQuery.extend.ajax jquery.js:7930
authenticate wts.js:5
(anonymous function) wts.js:27
jQuery.event.dispatch jquery.js:3045
elemData.handle jquery.js:2721
jQuery.event.trigger jquery.js:2957
(anonymous function) jquery.js:3639
jQuery.extend.each jquery.js:631
jQuery.fn.jQuery.each jquery.js:253
jQuery.fn.extend.trigger jquery.js:3638
H jquery.mobile-1.3.0.min.js:2
I jquery.mobile-1.3.0.min.js:2
jQuery.event.dispatch jquery.js:3045
elemData.handle jquery.js:2721
XMLHttpRequest cannot load CANTPOSTTHISURL/rest/session. Invalid HTTP status code 500 index.html:1
Sample of error data: error wts.js:16
readyState: 0
status: 0
responseText: wts.js:17
COMPLETE
和標題:
Request URL:CANTPOSTTHISURL/rest/session
Request Method:OPTIONS
Status Code:500 Internal Server Error
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:CANTPOSTTHISURL
Origin:http://127.0.0.1:8020
Referer:http://127.0.0.1:8020/ppm/index.html
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36
Response Headersview source
Access-Control-Allow-Origin:*
Connection:close
Content-Type:application/json
Date:Mon, 31 Mar 2014 13:24:36 GMT
Server:Wildfly 8
Set-Cookie:GEAR=local-53185956500446bd39000020; path=/
Transfer-Encoding:chunked
X-Powered-By:Undertow 1
ConsoleSearch
我認爲這是我發送的數據,但我也試過'{「用戶名」:「管理員」,「密碼」:「管理員」}或{「用戶名」:「管理員」,「密碼」:「管理員」}但沒有什麼變化。 一個重要的評論:我只能做POST或OPTION請求所以沒有jsonp 謝謝
+0
好吧,'500'響應代碼意味着服務器端出了問題。沒有看到代碼,幾乎不可能幫助 –