为什么url在ajax成功处理程序中的contextpath之后追加

时间:2017-05-17 09:13:04

标签: javascript jquery ajax

我正在尝试在ajax成功处理程序中的本地主机中打开google页面。这就是我到目前为止的尝试。

$(".write-portal").off("click").on("click",function (event) {   
var id = $(this).attr('id');
var pageId = $(this).attr('data-pageBodyId');
var windowUrl= window.location.href;        
var postData={"windowUrl":windowUrl};
$.ajax({
    type : "POST",
    url  : contextpath + "/perform-logout",
    data : postData,
    async:false,
    success : function(msg) {
         window.open("www.google.com","google",'width=700,height=600,left=0,top=100,screenX=0,screenY=100')
        //window.location.href = "www.google.com";
        /*if(msg){
            window.location.assign(customUrl);
        }*/
    },
    error : function(xhr, ajaxOptions, thrownError) {

    }
});
});

它会弹出一个弹出窗口,但网址为contextpath + www.google.com。但我只想要www.google.com

1 个答案:

答案 0 :(得分:1)

打开窗口时需要使用绝对URL。试试这个:

window.open("http://www.google.com", ...