我正在對控制器進行AJAX調用,並且我希望重定向到Success上的新頁面。所以我有我的成功回調函數中的重定向邏輯。但它不會重定向到新頁面,而是保持在同一頁面上。Spring MVC - 使用jQuery重定向
The intriguing thing is that a GET Request (with the form Data I just sent via POST) is made after the Ajax Callback is executed. that is, I see a GET Request in the Address Bar.
這裏是我的AJAX請求
$.ajax({
url: "processData",
type: "POST",
dataType: 'json',
contentType:'application/json',
async: false,
data: JSON.stringify(req),
success: function(result) {
url = window.location.href;
url = url.replace("processData", "getMoreData");
alert(url); // correct url is printed
window.location.replace(url);
},
error: function() {
alert("--- Failure ---");
}
});
有什麼錯在這裏?
在更改url後,將location.reload添加爲最後一條語句。我認爲它應該工作。 – NightsWatch
@PradeepSekar謝謝Pradeep,但它仍然不起作用。 – AgentX
我想知道!一旦你手動重新加載它的時候在窗口中有url,它會把你帶到你期待的地方? – NightsWatch