dojo/request/script通过JSONP实现跨域请求数据,需要后台配合返回Javascript代码:
require(["dojo/request/script","dojo/json"],function(script,JSON) { script.get(url,{ handleAs: "json",jsonp: 'jsonpcallback' }).then(function(data) { console.log(JSON.stringify(data)); }); });
请求url的形式:
http://url?param=bgh&jsonpcallback=dojo_request_script_callbacks.dojo_request_script0
响应头信息包含此内容:
Content-Type: application/javascript;charset=UTF-8响应内容:
dojo_request_script_callbacks.dojo_request_script0({"name":"bgh","note":"","success":true});