var jsonp = function() { var extend = function(obj, attrs) { for (var name in attrs) { obj[name] = attrs[name]; } }; var jsonp = function() { jsonp_imp.apply(null, arguments); }; extend(jsonp, { guid: 0, requests: {}, avail_tag: [], request_timeout: 5 //seconds }); var Request = function(obj) { extend(this, obj); this.init && this.init(); }; var oo = Request.prototype; oo.remove = function() { var js = this.js; js.parentNode.removeChild(js); js = null; delete jsonp.requests[this.id]; }; oo.on_complete = function() { if (this.success) { this.success(); this.success = null; } }; oo.on_timeout = function() { var state = this.js.readyState; if (state != "complete" && state != "loaded" && this.failed) { this.failed(); this.failed = null; } state = null; this.remove(); }; oo.init = function() { var request = this; this.js.onload = function() { request.on_complete(); }; setTimeout(function() { request.on_timeout(); }, request.timeout); }; var jsonp_imp = function(url, charset, timeout, failed, success) { var head = document.getElementsByTagName("head")[0]; var js = document.createElement("script"); head.appendChild(js); if (!charset) { charset = "utf-8"; } var id = jsonp.guid++; if (!timeout) { timeout = jsonp.request_timeout * 1000; } var now = new Date(); var request = new Request({ id: id, url: url, charset: charset, failed: failed, success: success, js: js, stat_time: now, timeout: timeout }); jsonp.requests[id] = request; js.charset = charset; js.src = url; return id; }; return jsonp; }(); var url = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.js"; var url2 = "http://saic-sis.escdn.com/api.php?op=get_linkage_xjw&parentid=10000000000004&act=ajax_getlist&keyid=1&callback=cb"; jsonp(url2 , null, 5000, function(){alert("failed");}, function(){alert("load ok");} ); function cb(d) { console.log(d); }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/78927.html
摘要:代码第日前瞻中国冲击金博尔特再战米羽球正直播柴飚洪炜出战男双力争会师决赛女排将死磕巴西郎平安排男陪练模仿对方核心执行结果用,不跨域的打开发送请求时,请求头内部没有当我用打开,出现跨域时。 一、同源策略 浏览器出于安全方面的考虑,只允许与本域下的接口交互(当前页面得url必须和接口得url是同源的)。不同源的客户端脚本在没有明确授权的情况下,不能读写对方的资源。 1、本域 同协议:如都是...
阅读 2931·2021-11-25 09:43
阅读 3293·2021-11-24 09:39
阅读 2804·2021-09-22 15:59
阅读 1914·2021-09-13 10:24
阅读 492·2019-08-29 17:02
阅读 2080·2019-08-29 13:23
阅读 3043·2019-08-29 13:06
阅读 3505·2019-08-29 13:04