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); }
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/78927.html
摘要:代碼第日前瞻中國沖擊金博爾特再戰米羽球正直播柴飚洪煒出戰男雙力爭會師決賽女排將死磕巴西郎平安排男陪練模仿對方核心執行結果用,不跨域的打開發送請求時,請求頭內部沒有當我用打開,出現跨域時。 一、同源策略 瀏覽器出于安全方面的考慮,只允許與本域下的接口交互(當前頁面得url必須和接口得url是同源的)。不同源的客戶端腳本在沒有明確授權的情況下,不能讀寫對方的資源。 1、本域 同協議:如都是...
閱讀 2957·2021-11-25 09:43
閱讀 3332·2021-11-24 09:39
閱讀 2840·2021-09-22 15:59
閱讀 2193·2021-09-13 10:24
閱讀 516·2019-08-29 17:02
閱讀 2108·2019-08-29 13:23
閱讀 3068·2019-08-29 13:06
閱讀 3546·2019-08-29 13:04