简体   繁体   English

在客户端加载外部脚本

[英]loading externals script on client side

I'm using this method when file is loaded: 加载文件时,我正在使用此方法:

$("<script/>", { "class": "test", "src": 'http://www.externalSite.com/js/xxx.js' }).appendTo("head");

the file is loaded fine and no problem with it. 该文件加载良好,没有问题。

Im try to make an ajax call in this file to get some data from the server DB, and then simply alert the result. 我尝试在此文件中进行ajax调用,以从服务器数据库中获取一些数据,然后简单地警告结果。

When Im making the call from the same server it works good, but when Im trying to call this script from an outside server it alerts an empty string 当我从同一服务器发出呼叫时,它工作正常,但是当我试图从外部服务器调用此脚本时,它会警告一个空字符串

Ajax不能用于从另一台服务器获取数据,这被称为同一原始策略,主机名和端口号必须相同才能发出请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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