2012-11-27 238 views
4

我在嘗試刪除值時收到以下彈出窗口。我正在使用jQuery Ajax刪除值。我使用的編程語言是python2.7和框架的Django 1.3.2嘗試使用jQuery Ajax刪除時獲得警報刪除

我的代碼如下:

$.ajax({ 
    type: "DELETE", 
    url: window.location.pathname + id + '/data-centers/' + dc, 
    contentType: 'application/html; charset=utf-8', 
    data: { 
     dc : dc, 
    }, 
    success: function(){ 
     alert("success"); 
    } 
    etc... 

當我確定要刪除我與JavaScript得到以下彈出值他說:

"This web page is being redirected to a new location. Would you like to resend 
the form data you have typed to the new location? 

而在阿賈克斯頭,我可以看到下面的(它試圖重定向到其他位置,但不知道爲什麼):

Connection Keep-Alive 
Content-Encoding gzip 
Content-Length 251 
Content-Type text/html; charset=iso-8859-1 
Date Tue, 27 Nov 2012 13:53:44 GMT 
Keep-Alive timeout=5, max=100 
Location http://www.test.com/403/test-403.html 
Vary Accept-Encoding 
Request Headers 
Accept */* 
Accept-Encoding gzip, deflate 
Accept-Language en-us,en;q=0.5 
Connection keep-alive 
Content-Length 12 
Content-Type application/html; charset=utf-8 

這隻發生在我嘗試使用DELETE時。

+5

您正被重定向到403(禁止)頁面。我想解決方案是授權您的服務器/應用程序/控制器上的http DELETE動詞 – jbl

回答

0

根據你的代碼,我發現可能是由於ajax的路徑不正確或ajax調用html可能有一些錯誤發生可能有一些重定向問題。因此,如果路徑是不正確的,那麼你可以用不同類型的varaible的設置遵循


$(location).attr('href'); 

$(document).ready(function() { 
    var pageurl = window.location; 
}); 

var currentpageURL = window.location.href; 

var currentpagepath = getAbsolutePagePath(); 

function getAbsolutePagePath() { 
    var pageurl = window.location; 
    var pathName = pageurl.pathname.substring(0, pageurl.pathname.lastIndexOf('/') + 1); 
    return pageurl.href.substring(0, pageurl.href.length - ((pageurl.pathname + pageurl.search + pageurl.hash).length - pathName.length)); 
} 

也許這將幫助你