仅在IE 10中工作的CORS响应,对于chrome和firefox失败 [英] CORS response working in IE 10 only, fails for chrome and firefox

查看:93
本文介绍了仅在IE 10中工作的CORS响应,对于chrome和firefox失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello,

I am making a cross origin ajax HTTP request from 'http://localhost:8080/[some string value].html' to a remote server machine.Actually this request is made to get a list of HDFS file system information which is installed in the remote server. Request URL is:
 
var formURL =  http://[remote server name]:[port number]/**webhdfs**/v1/xd/?op=LISTSTATUS. 

 and the ajax call is like:
 $.ajax({
		url: formUrl,
		dataType: 'json',
		success: function(response)
 		{
            alert("Response is: "+response);
        }
});

response is expected a json array like below

{"FileStatuses":{"FileStatus":[
{"accessTime":1449652575549,"blockSize":134217728}]}}

While I am getting this response in IE 10, but for all other browsers it's  throwing a browser level error as:

"XMLHttpRequest cannot load http://[remote server name]:[port number]/**webhdfs**/v1/?op=LISTSTATUS. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access."

I searched google, its solution is to write java servlet method to set response header as "Access-Control-Allow-Origin, http://localhost:8080".

As this ajax request is not meant for any server side java method as ajax request generally does, how can I get rid this issue? 

推荐答案

.ajax({
url:formUrl,
dataType:' json'
成功:函数(响应)
{
alert( 响应是: +响应);
}
});

响应 期望json数组如下

{ FileStatuses:{ FileStatus:[
{ accessTime 1449652575549 blockSize 134217728 }]}}

当我收到 响应 IE 10 ,但 所有其他浏览器' 抛出浏览器级错误:

XMLHttpRequest无法加载http:// [远程服务器名称]:[端口号] / * * webhdfs ** / v1 /?op = LISTSTATUS。否'
Access-Control-Allow-Origin ' 标头出现在请求的资源上。原因' http: // localhost:8080'因此不允许访问。

我搜索了谷歌,其解决方案 将java servlet方法写入 set 响应header as Access-Control-Allow-Origin,http :// localhost:8080

As ajax请求并不意味着 任何服务器端java方法作为 ajax请求通常会做什么,我怎么能 get rid 问题?
.ajax({ url: formUrl, dataType: 'json', success: function(response) { alert("Response is: "+response); } }); response is expected a json array like below {"FileStatuses":{"FileStatus":[ {"accessTime":1449652575549,"blockSize":134217728}]}} While I am getting this response in IE 10, but for all other browsers it's throwing a browser level error as: "XMLHttpRequest cannot load http://[remote server name]:[port number]/**webhdfs**/v1/?op=LISTSTATUS. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access." I searched google, its solution is to write java servlet method to set response header as "Access-Control-Allow-Origin, http://localhost:8080". As this ajax request is not meant for any server side java method as ajax request generally does, how can I get rid this issue?


检查这个 - https://code.google.com/p/chromium/issues/detail?id = 96007 [ ^ ]。
Check this out - https://code.google.com/p/chromium/issues/detail?id=96007[^].


这篇关于仅在IE 10中工作的CORS响应,对于chrome和firefox失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆