4

尝试删除值时出现以下弹出窗口。我正在使用 jQuery Ajax 删除该值。我使用的编程语言是python2.7,框架是Django 1.3.2

我的代码如下:

$.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?

在 Ajax 标头中,我可以看到以下内容(它试图重定向到其他位置,但不知道为什么):

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 时。

4

1 回答 1

0

根据您的代码,我发现可能是由于 ajax 的路径不正确或 ajax 调用 html 可能有一些重定向问题而发生了一些错误。因此,如果路径不正确,那么您可以设置不同类型的变量,如下所示


$(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));
}

愿这对你有帮助

于 2013-01-07T09:41:39.013 回答