Nigel Wu
Nigel Wu

Reputation: 195

cross-domain issue in IE

I'm current working on some stuff that need to send cross-domain ajax requests. I'm using jQuery 1.7.2 and Resteasy. Here is my ajax request:

 $.ajax({
    url: Configuration.AjaxUrlPrefix + "/rest/conf/saveoption",
    data: {
        save_option: JSON.stringify(optionData)
    },
    type: "POST",
    dataType: 'text',
    success: success,
    error: fail,
    cache: false
});

And I use a interceptor to add some headers to my rest responses:

@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", "*");
    }

}

It works well in Chrome and FF, but not work in IE8 and IE9. And I didn't see any error in IE developer tool. Could anyone help me?

Upvotes: 0

Views: 1119

Answers (1)

otakustay
otakustay

Reputation: 12395

IE8-9 should use XDomainRequest to fire cross-domain ajax request and jQuery does not support it natively, I find a ticket on jQuery bug tracker: http://bugs.jquery.com/ticket/8283

jQuery team may consider XDomainRequest not completely compatible to its ajax interface so has decided not to support it, however a plugin may be helpful: https://github.com/jaubourg/ajaxHooks/blob/master/src/ajax/xdr.js

Remember xdr transport has some limitation, check discussion of the jQuery ticket above

Upvotes: 1

Related Questions