前端框架 ExtJs //币种代码 var currencys = [ {curCode: 'USD'}, {curCode: 'CNY'}, {curCode: 'HKD'}, ]; setInterval(function () { for (var idx = 0, len = currencys.length; idx < len; idx++) { for (var itx = 0, len2 = currencys.length; itx < len2; itx++) { let scur = currencys[idx].curCode; let tcur = currencys[itx].curCode; if (scur == tcur) continue; //测试url次数有限 let url = 'http://api.k780.com:88/?app=finance.rate&' + 'scur=' + scur + '&tcur=' + tcur + '&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4' console.info(url); Ext.Ajax.request({ url: url,//这里是填写需要跨域访问的URL cors: true, useDefaultXhrHeader: false, method: 'get', //async: false,//可开启同步 headers: { "Origin:": 'http://api.k780.com',//这里是填写需要跨域访问的URL Origin字段用来说明,本次请求来自哪个源 "Access-Control-Allow-Origin": 'http://api.k780.com',//这里是填写需要跨域访问的URL "Access-Control-Allow-Credentials": true, "Content-Type": 'application/json' //文件上传的格式, }, success: function (res, opts) { var text = res.responseText; //{"success":"1","result":{"status":"ALREADY","scur":"USD","tcur":"CNY","ratenm":"美元/人民币","rate":"7.0677","update":"2019-12-04 10:14:04"}} console.info(text); }, }); } } }, 60 * 60 * 1000);
参考 EXTJS 使用Ajax跨域上传文件