我目前正在研究一些需要发送跨域ajax请求的东西。 我正在使用jQuery 1.7.2和Resteasy。 这是我的ajax请求:
$.ajax({
url: Configuration.AjaxUrlPrefix + "/rest/conf/saveoption",
data: {
save_option: JSON.stringify(optionData)
},
type: "POST",
dataType: 'text',
success: success,
error: fail,
cache: false
});
我使用拦截器为我的其余回复添加一些标题:
@Provider
@ServerInterceptor
public class CrossDomainInteceptor implements PostProcessInterceptor
{
@Override
public void postProcess(ServerResponse response)
{
MultivaluedMap<String, Object> metadata = response.getMetadata();
metadata.add("Access-Control-Allow-Origin", "*");
metadata.add("Access-Control-Allow-Methods", "*");
metadata.add("Access-Control-Max-Age", "*");
metadata.add("Access-Control-Allow-Headers", "*");
}
}
在Chrome和FF中运行良好,但在IE8和IE9中无效。我没有在IE开发人员工具中看到任何错误。 有谁可以帮助我?
答案 0 :(得分:1)
IE8-9应该使用XDomainRequest
来触发跨域ajax请求,而jQuery 本身不支持支持它,我在jQuery bug跟踪器上找到了一张票:http://bugs.jquery.com/ticket/8283 < / p>
jQuery团队可能会认为XDomainRequest
与其ajax界面不完全兼容,因此决定不支持它,但插件可能会有所帮助:https://github.com/jaubourg/ajaxHooks/blob/master/src/ajax/xdr.js
请记住xdr transport有一些限制,请检查上面jQuery票证的讨论