制作一个与协议无关的jQuery ajax调用协议、jQuery、ajax

由网友(持刀战情场)分享简介:我们有嵌入在各个网站的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,
    ...
});
 
关于jquery用ajax调用文本 完全跟网上教程一样的写,却总是不对 以下代码主要的列出来求大师

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,
    ...
});

阅读全文

相关推荐

最新文章