window.location.href关于Ajax的成功不工作 [英] window.location.href on ajax success not working

查看:1913
本文介绍了window.location.href关于Ajax的成功不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图解决现在这一段时间,但我不能让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.

这篇关于window.location.href关于Ajax的成功不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆