将学习变成乐趣,一直在路上
每天1990

导航

 
问题:使用ajax跳转到新页面无效(浏览器Safari)
 
window.open("{% url "runtestinfo" %}")
 
但是使用location能够在原页面跳转
 
解决方法:
1.将ajax的async改为false
2.先定义变量为window.open()对象,然后使用location跳转
var w = window.open();
w.location=("{% url "runtestinfo" %}")
 
 
具体代码如下:
 
$.ajax({
                    cache: true,
                    type: "POST",
                    url:"{% url "save_testsuit" %}",
                    data:{caseinfos:JSON.stringify(selectcase)},
                    async: false,
                    error: function(request) {
                        alert("保存失败");
                    },
                    success: function(data) {
                        if(data.respcode==0){
                            alert("页面信息保存成功");
 
                            var w = window.open();
                            w.location=("{% url "runtestinfo" %}")
                        }
                        else{
                            alert(JSON.stringify(selectcase))
                            alert(data.msg);
                        }
                    }
 });
 
 
原因:参考下面的文章解决的,博主说是因为弹框被拦截了
posted on 2017-06-15 10:48  每天1990  阅读(2206)  评论(0编辑  收藏  举报