简体   繁体   中英

redirect with javascript to another domain with Json

I'm retrieving an url from a php file with Json , and then in the success part I do

window.location=msg.message

but the proble is that if we suppose my domain is http example.com and the msg.message value is

https://otherdomain.com

the redirection is done to http:/example.com/https:/otherdomain.com how can I go directly to https:/otherdomain.com code

     $.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")

You need two stashes before the host part of the URL.

https://otherdomain.com

You have only one ( https:/otherdomain.com ).

(And href is a string, not a function, assign a value to it as you do in the first code block, don't try to call it as you do in the third).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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