0
我做了一個ajax調用。它是通過content_script.js通過Chrome擴展生成的。完成後,應提醒返回的消息。但是,警報將響應顯示爲空白。Django/JS:Ajax響應沒有得到消息
content_script.js
function got_response(){
alert(xmlHttp.responseText);
}
var xmlHttp=new XMLHttpRequest();
xmlHttp.open("POST", domain, true);
xmlHttp.onreadystatechange = got_response;
xmlHttp.send();
view.py:
return HttpResponse("login_error")
我得到一個警告信息,但它不包括我的消息 「login_error」。我設置了斷點,它肯定會從那裏返回。看起來這有時起作用,有時不起作用。就像它進入的狀態一樣?
編輯:這似乎發生時request.user是匿名的(也是錯誤的,因爲我登錄)
對'的返回類型onreadystatechange'是'xmlhttp.status,xmlhttp.responseText'。你能把'got_response'的簽名改成'got_response(status,responseText)'和'alert(responseText)'嗎? [這篇文章](http://stackoverflow.com/a/16369406/1628832)應該幫助 – karthikr
提醒「undefined」 – user984003
你可以提醒(狀態)?我有一種感覺,CSRF中間件阻止了你嘗試POST,並且你沒有做任何錯誤處理。 – Thomas