2013-07-10 63 views
0

我有一個ajax函數應該在完成時重定向頁面。在這一點上,我不在乎它是成功還是失敗,所以我在.always()中使用它。它會執行我放入其中的任何內容,如alert()聲明或console.log()聲明。但是,由於某種原因,window.location.replace("http://stackoverflow.com");window.location.href = ("http://stackoverflow.com");不會使任何事情發生。 控制檯中也沒有錯誤。Ajax函數在完成時不會重定向我的頁面

這裏的AJAX:

function createAdd(event, user){ // Creates a custom event and automatically gives creator ownership 
    var name = document.getElementById('name').value; 
    var loc = document.getElementById('loc').value; 
    var start = document.getElementById('datepicker').value; 
    var end = document.getElementById('datepicker2').value; 
    var tags = document.getElementById('tags').value; 
    var jqxhr = $.ajax("/eventsearch/eventsearch/createCustom/", { 
    type: "POST", 
    data: {name: name, loc: loc, start: start, end: end, tags: tags, event_id: event, profile: user} 
    }) 
    .always(function() { window.location.replace("/eventsearch/eventsearch"); 
    alert("hello") }) 
} 

警報執行。

+0

替換()是一個字符串的功能。只需使用equals設置值即可。 –

+0

還有其他的東西在這裏..你可以請創建一個jsFiddle? – DevlshOne

+0

以前從未做過小提琴,但這裏是我的。讓我知道你是否需要我改變一些事情。 http://jsfiddle.net/n22dX/1/ – Xonal

回答

0
window.location.replace("/eventsearch/eventsearch") 

應該是

window.location = "/eventsearch/eventsearch"; 
location.reload(); 
+0

什麼都沒發生:/ – Xonal

+0

我遺漏了一半。 – DevlshOne

+0

是的,我嘗試了有和沒有 – Xonal

相關問題