繁体   English   中英

使用Json使用javascript重定向到另一个域

[英]redirect with javascript to another domain with Json

我正在使用Json从php文件中检索URL,然后在成功部分中,我做了

window.location=msg.message

但是问题是,如果我们假设我的域名是http example.com,而msg.message值是

https://otherdomain.com

重定向到http:/example.com/https:/otherdomain.com如何直接转到https:/otherdomain.com代码

     $.ajax({
   type: "POST",
   url: "ajax.php",
   data: dataString,
   dataType: "json",
   success: function (msg){
        $.fn.colorbox.close();//close the box
        alert(decodeURI(msg.message));//
        window.location.href(msg.message); // goes to domain.com/msg.message        
      },
   });

请使用分配方法:

window.location.assign("https://otherdomain.com")

URL的主机部分之前需要两个存储区。

https://otherdomain.com

您只有一个( https:/otherdomain.com )。

(并且href是一个字符串,而不是一个函数,请像在第一个代码块中那样为它分配一个值,不要像在第三个代码块中那样尝试调用它)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM