chrome 插件开发 jsonp 无法使用

来源:互联网 发布:数值最优化 pdf 编辑:程序博客网 时间:2024/05/22 20:27

jquery ajax代码,但chrome插件无法使用

在正常的网页下执行如下代码能够得到ajax的数据,但在插件环境下执行则不能

//淘宝的物流接口,该接口可能长期有效//直接在任何页面打开控制台输入此代码(jquery需要支持此ajax代码),将获取ajax数据。var testUrl = 'https://lsp.wuliu.taobao.com/locationservice/addr/output_address_town_array.do';var data={       "l1":'340000',       "l2":'340100',       "l3":'340111',       "lang":"zh-S"      }$.ajax({      type: 'GET',      url: testUrl,      data: data,      jsonp:"callback",      success: function(result){         console.log(result);      },      dataType: "jsonp"});

jquery ajax代码,兼容chrome 插件开发

//此代码兼容chrome插件环境,但无法跨域,如需跨域需要在mainfest.json添加//"permissions": [ "http://*.taobao.com/*"]//ajax回调函数function town_address_callback(result){    console.log(result);}var testUrl = 'https://lsp.wuliu.taobao.com/locationservice/addr/output_address_town_array.do';var data={      "l1":'340000',      "l2":'340100',      "l3":'340111',      "lang":"zh-S",      "callback":"town_address_callback"//回调函数的名称,需要在环境中定义此函数。    }$.ajax({      type: 'GET',      url: testUrl,      data: data,      success: function(result){         eval(result);//将返回的文本数据作为js代码执行。      },      dataType: "text"//用文本的方式接受ajax数据。});
0 0
原创粉丝点击