本文介绍了仅在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? 

推荐答案



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

09-27 11:57