2012-11-27 201 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)); 
} 

也许这将帮助你