由网友(持刀战情场)分享简介:我们有嵌入在各个网站的Widget。愿我们的小部件根据我们所嵌入网站的协议(HTTP或HTTPS)进行Ajax调用到我们的服务器。是否有一个常见的做法,这样做呢?使用协议无关的网址(见下文)不工作:$。阿贾克斯({网址://cdn.example.com/serviceName,...});解决方案 也不会转回...
我们有嵌入在各个网站的Widget。愿我们的小部件根据我们所嵌入网站的协议(HTTP或HTTPS)进行Ajax调用到我们的服务器。 是否有一个常见的做法,这样做呢?
使用协议无关的网址(见下文)不工作:
$。阿贾克斯({
网址://cdn.example.com/serviceName,
...
});
解决方案
也不会转回去这项工作?
VAR myUrl =(window.location.protocol +'//cdn.example.com/serviceName');
$阿贾克斯({
网址:myUrl,
...
});
We have a widget that is embedded in various website. We would like the widget to make an ajax call to our server according to the protocol (http or https) of the website in which we are embedded. Is there a common practice to do that?
Using a protocol agnostic url (see below) doesn't work:
$.ajax({
url : '//cdn.example.com/serviceName',
...
});
解决方案
Wouldn´t this work?
var myUrl = (window.location.protocol + '//cdn.example.com/serviceName');
$.ajax({
url : myUrl,
...
});
相关推荐
最新文章