var jsonData = { "dataid": dataid, "title": title, "thisDay": thisDay, "time": time }; //刪除記錄需要提交到服務器 $.ajax({ type: "POST", url: "http://192.168.1.9:8090/agenda/deleteEvent/", contentType: "application/json; charset=utf-8", data: JSON.stringify(jsonData), dataType: "json", async: true, timeout: 50000, success: function(msg){ alert("Data delete success:"+JSON.stringify(msg)); }, error: function(msg){ alert("Data delete failed:"+JSON.stringify(msg)); } });
在IE上測試OK ,能返回內容,但是在firefox上不行。走進error,返回如下信息。
"readyState":0,"responseText":"","status":0,"statusText":"error"
說明send沒有發送。在網上搜了一些,還是沒有解決,記錄一下,明天繼續找解決方案
-----------------------------------------------------------------------------------------------
今天打開電腦,重啟django服務器,再進頁面,竟然離奇般的好了, readState是4了。。。。。。。。。。好神奇,搞不懂什么原因。。。。。。。。。。
之前網上瀏覽了很多方法,跨站訪問呀,格式呀,等等,都部適用,真是造化弄人。
CSRF 保護機制,我直接屏蔽掉了。
views.py里
from django.views.decorators.csrf import csrf_exempt
在我的處理函數前加上裝飾器
@csrf_exempt
終於成功了,