簡體   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