(转)解决“No 'Access-Control-Allow-Origin' header is present on the requested resource”

来源:互联网 发布:中航微电子重庆 知乎 编辑:程序博客网 时间:2024/06/14 05:15

原地址:http://blog.csdn.net/cryhelyxx/article/details/43761887


1. 问题描述

在js中使用ajax请求在网页控制台下打印以下错误信息:

XMLHttpRequest cannot load http://192.168.2.46:8000/account/getjson/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.

本人的ajax代码如下

var jsontree = [];$.ajax({    url: "http://192.168.2.46:8000/account/getjson/",    type: "GET",    dataType: 'JSON',    success: function(result){        jsontree = result;    }});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2. 解决方法

将上面的dataType: 'JSON'替换为dataType: 'JSONP'即可。

OK, Enjoy it!!!


阅读全文
0 0