在使用jquery的ajax方法获取数据时,遇到了错误提示“No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”查了一下百度,这个问题和安全机制有关,默认不允许跨域调用。
处理手段:使用jsonp格式, ajax请求参数dataType:’jsonp’。
$.ajax({
url: "http://.......",
type: 'get',
dataType: 'jsonp',//here
success: function (data) {
//...
}
});