[英]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 我正在使用Json从php文件中检索URL,然后在成功部分中,我做了
window.location=msg.message
but the proble is that if we suppose my domain is http example.com and the msg.message
value is 但是问题是,如果我们假设我的域名是http example.com,而msg.message
值是
https://otherdomain.com
the redirection is done to http:/example.com/https:/otherdomain.com how can I go directly to https:/otherdomain.com code 重定向到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")
You need two stashes before the host part of the URL. URL的主机部分之前需要两个存储区。
https://otherdomain.com
You have only one ( https:/otherdomain.com
). 您只有一个( 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). (并且href
是一个字符串,而不是一个函数,请像在第一个代码块中那样为它分配一个值,不要像在第三个代码块中那样尝试调用它)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.