我一直在试图解决现在这一段时间,但我不能让itworking。当用户点击一个链接他要求确认,他希望借此行动。然后一个AJAX调用。这就是所谓的脚本工作正常,并返回一个字符串,其中重定向到。
I've been trying to solve this for a while now, but I can't get itworking. When a user clicks a link he's asked to confirm that he wants to take this action. Then a ajax call is made. The script that's called works fine and returns a string where to redirect to.
我在这里看到几个职位上的问题了window.location,buth没有一个人能解决我的。
I've seen several posts here on problems with window.location, buth none of them could solve mine.
我的code:
function confirm(a,b,c){
var r=confirm("Are you sure to do this?");
if(r==true){
$.ajax({
type: "POST",
url: "/process-action.php",
async: false,
data: {a:a,b:b,c:c},
success: function(data){
window.location.href = data;
}
});
} else {
return false;
}
}
如果我这样做警报(数据)
而不是 window.location.href =数据
我可以看到,正确的数据传递。例如/用户/主页。然而,重定向不会发生。
If I do alert(data)
instead of window.location.href = data
I can see that the correct data is passed. For instance /user/homepage. Yet, the redirection is not taking place.
如果想更换整个URL的相对路径,但也不能工作。
If tried to replace the relative path with the entire url, but that didn't work either.
尝试使用分配()
来代替:
window.location.assign(data);
window.location.href
是一个属性,不是方法。
window.location.href
is a property, not a method.