使用 JavaScript 重定向到 JSON 的另一个域

redirect with javascript to another domain with Json

本文关键字:另一个 JSON JavaScript 重定向 使用      更新时间:2023-09-26

我正在使用 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是一个字符串,而不是一个函数,像在第一个代码块中一样为它赋值,不要像在第三个代码块中那样尝试调用它)。