我写了一个odsserver.aspx的程序,这个程序相当于一个公用的借口,供大家调用返回json串结果。
但是当一个程序在调用的时候,提示 NO‘access-control-allow-origin’header is present on
the requested resource. 应该是跨域ajax访问出的问题。
前台的这个程序就是.net +js通过ajax方式调用的odsserver.aspx程序,请问下我该具体怎么处理这个问题呢?
http://blog.csdn.net/cryhelyxx/article/details/43761887
在odsserver.aspx所在的网站的根目录添加一个叫做crossdomain.xml的文件,内容为:
<?xml version="1.0" ?>
重启server,重试
<?xml version="1.0" ?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
如果还不行可以试一下:
var jsontree = [];
$.ajax({
url: "http://192.168.2.46:8000/account/getjson/",
type: "GET",
dataType: 'JSON',
success: function(result){
jsontree = result;
}
});
将上面的dataType: 'JSON'替换为dataType: 'JSONP'
贴给你
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;
}
});
2. 解决方法
将上面的dataType: 'JSON'替换为dataType: 'JSONP'即可。
OK, Enjoy it!!!
好吧,请在试试这个
http://blog.sina.com.cn/s/blog_6f3749920102v22p.html
设置header
access-control-allow-origin:*