1. /**********************************************************
  2.  
  3. 说明:跨域请求数据Javascript组件
  4. ----------------------------------------------------------
  5. add by OceanHo 2015-4-13 18:18:14
  6. **********************************************************/
  7. ; (function (window, undefined) {
  8.  
  9. var _ap = function () {
  10. }, _asyncID = 2048, _asyncType = "asynctype", _version = "1.5.0", _cbKey = "cb", _cb = "";
  11.  
  12. function addSc(url, cbAndParam) {
  13. var script = createSc();
  14. script.setAttribute("src", url + "?" + cbAndParam);
  15. window.document.getElementsByTagName("head")[0].appendChild(script);
  16. };
  17.  
  18. function delSc(id) {
  19. var scripts = getSc();
  20. for (var i = 0; i < scripts.length; i++) {
  21. if (scripts[i].attributes["id"]) {
  22. if (parseInt(scripts[i].attributes["id"].value) === parseInt(id)) {
  23. remove(scripts[i]);
  24. }
  25. }
  26. }
  27. };
  28.  
  29. function remove(script) {
  30. if ((script) && (script.parentNode)) {
  31. script.parentNode.removeChild(script);
  32. }
  33. };
  34.  
  35. function clearSc() {
  36. var scripts = getSc();
  37. for (var i = 0; i < scripts.length; i++) {
  38. remove(scripts[i]);
  39. }
  40. };
  41.  
  42. function getSc() {
  43. var s1 = [];
  44. var scripts = window.document.getElementsByTagName("script");
  45. for (var i = 0; i < scripts.length; i++) {
  46. if (scripts[i].attributes["async"]) {
  47. if (scripts[i].attributes["async"].value === _asyncType) {
  48. s1.push(scripts[i]);
  49. }
  50. }
  51. }
  52. return s1;
  53. };
  54.  
  55. function createSc() {
  56.  
  57. _asyncID++;
  58. var script = window.document.createElement("script");
  59. script.setAttribute("id", _asyncID);
  60. script.setAttribute("async", _asyncType);
  61. script.setAttribute("type", "text/javascript");
  62.  
  63. script.onload = script.onreadystatechange = function () {
  64.  
  65. if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
  66.  
  67. delSc(this.attributes["id"].value);
  68.  
  69. script.onload = script.onreadystatechange = null;
  70. }
  71. }
  72. return script;
  73. }
  74.  
  75. function waitDel(id, interval) {
  76. window.setInterval(delSc(id), interval);
  77. };
  78.  
  79. _ap.fn = _ap.prototype = {
  80. constructor: _ap,
  81. version: _version,
  82. init: function (arg) {
  83. return new _ap().constructor;
  84. },
  85.  
  86. get: function (url, cbk, cb, param) {
  87. if (!cb) cb = _cb;
  88. if (!cbk) cbk = _cbKey;
  89. var qs = this.map(',', param);
  90. addSc(url, _cbKey + "=" + cb + "&" + qs);
  91. },
  92.  
  93. getEasy: function (url, cb, param) {
  94. if (!cb) cb = _cb;
  95. var qs = this.map(',', param);
  96. addSc(url, _cbKey + "=" + cb + "&" + qs);
  97. },
  98.  
  99. getCustom: function (url, param) {
  100. addSc(url, this.map(',', param));
  101. },
  102.  
  103. map: function (split, params) {
  104. var str, strs = [];
  105. if (typeof params != "string") {
  106. params = eval(params);
  107. for (var p in params) {
  108. strs.push(p + "=" + params[p])
  109. }
  110. str = strs.join(split);
  111. } else {
  112. str = param;
  113. }
  114. return str;
  115. },
  116. clear: function () { clearSc(); }
  117. };
  118.  
  119. _ap.fn.init.prototype = _ap.fn;
  120.  
  121. window.CrossLoad = _ap.fn.init();
  122.  
  123. })(window);
  124.  
  125. // 使用 、
  126. <script>
  127. window.CrossLoad.getEasy("https://www.oceanho.com/common/chat/v2","ReciveMessageHandler",{})
  128.  
  129. function ReciveMessageHandler(msg){
  130.  
  131. }
  132. </script>

script通过script标签跨域加载数据的更多相关文章

  1. jquery中ajax跨域加载

    今天学习ajax跨域加载,先来一段代码,异步加载的链接是爱奇艺的开源,我直接拿来用作测试 <!DOCTYPE html> <html lang="en"> ...

  2. jquery mobile 和phonegap开发总结之三跨域加载页面

    跨域加载 一要进行一定的配置见下面 $( document ).bind( "mobileinit", function() { // Make your jQuery Mobil ...

  3. RequireJS跨域加载html模版后被转成JS问题分析及解决

    问题描述 RequireJS跨域加载HTML模版失败,例如: 在a.com域名下请求CDN域名下的模版,text.js插件会把html文件转成html.js文件去加载,由于并没有生成html.js文件 ...

  4. chrome浏览器下用jQuery的load函数来跨域加载页面,响应状态status为(canceled)是什么情况? JSON和JSONP,也许你会豁然开朗,含jQuery用例

    http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html 问题来源:http://q.cnblogs.com ...

  5. JQuery和原生JS跨域加载JSON数据或HTML。

    前提:有时候需要在网页上,加载另一个网站上的数据.或者加载另一个网站上的一个页面.Js的Ajax请求不具备跨域功能,可以使用JQuery来实现. 网页端JS代码: $(function () { $. ...

  6. pdf.js跨域加载文件

    pdf.js一个基于Html的工具类,熟悉pdf.js的朋友们很清楚,pdf.js帮助我们做了很多事.尤其金融类网站会产生很多的报表.需要在线预览.pdf.js绝对是我们的首选 本地预览 在pdf.j ...

  7. flash 跨域加载 二次加载

    var url2:String = "http://thirdapp0.qlogo.cn/qzopenapp/fa5d80ebf9fc89aaa1d7ddb0e1b861e58d77b409 ...

  8. script标签跨域的缺点

    1,只支持GET,不支持其他例如:put,delete,post等 2,想拿到数据需要服务器端做出相应处理,必须在window域下面有对应的执行函数.例如:window.callbackHandler ...

  9. 使用script的src实现跨域和类似ajax效果

    在解决js的跨域问题的时候, 有多种方式, 其中有一种是利用script标签的src属性,因为这个属性是不受域名限制的,我们可以直接让src的这个链接指向跨域网站的一个接口, 这个接口返回的是js代码 ...

随机推荐

  1. Python实现接口测试中的常见四种Post请求数据

    前情: 在日常的接口测试工作中,模拟接口请求通常有两种方法, 利用工具来模拟,比如fiddler,postman,poster,soapUI等 利用代码来模拟,使用到一些网络模块,比如HttpClie ...

  2. mysql关键字了解

    unsigned  无符号 就是没有负数 列-1  -2 auto_increment 自增 comment 注释 primary key 主键 foreign key ()   references ...

  3. 第51章 设置FLASH的读写保护及解除—零死角玩转STM32-F429系列

    第51章     设置FLASH的读写保护及解除 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.co ...

  4. java基础必备单词讲解 day two

    variable 变量 count 统计 sum 总数 salary 薪水 Scanner 接收 import 导入 eclipse 日食 control 控制 shift 改变 alt 替换键 ha ...

  5. Docker自学纪实(四)搭建LNMP部署wordpress

    我们在工作中最常用的就是LNMP网站平台 这个架构呢,是整个公司网站的核心 如果对于访问量较小的网站,可以直接在服务器上面部署 而如果是访问量很大的网站,那负载就是个很大的问题. 要么需要再买很多服务 ...

  6. linux下Tomcat配置提示权限不够解决办法

    在终端输入命令 sudo chmod -R 777 /opt/Tomcat,那么Tomcat文件夹和它下面的所有子文件夹的属性都变成了777(读/写/执行权限)

  7. 使用file_get_contents()和curl()抓取网络资源的效率对比

    使用file_get_contents()和curl()抓取网络资源的效率对比 在将小程序用户头像合成海报的时候,用到了抓取用户头像对应的网络资源,那么抓取方式有很多,比如 file_get_cont ...

  8. 关于ZYNQ-700是否支持大容量SD卡汇报

    关于ZYNQ-700是否支持大容量SD卡 不支持. 下午问了客服的FAE给的答案是不清楚,我自己调研了一下为什么. 调查结果: 1. 大容量的SD卡为什么不支持? SD2.0规范中(SDHC)硬件支持 ...

  9. Gson杂记录

    //Integer userId = getUserId(); //System.out.println("userId:"+userId); /*for(int i=0;i< ...

  10. manjaro无法使用ifconfig查ip

    manjaro中自带的查看网络的命令是: ip addr 可以了解一下ip命令都有哪些功能 如果还是想要 ifconfig 需要安装net-tools 安装命令: sudo pacman -S net ...