0

I have been having a hard time finding a good solution for this. I have a sub-domain that is meant to provide secondary services to a site. Like suggestive selling, etc. I have created one code that will submit a ajax post for tracking. The second ajax call will grab html, and post it to a div. This works great in IE10, Chrome, Safari, and Firefox. But doesn't work in IE 7-9.

I have found many post, that semi-explain a solution. But non have seemed to work for me. Does anyone have experience with dealing with this? Help is much appreciated.

// TRACKER
function log() {
$.ajax({url:"http://sub.differentdomain.com/in/li/", dataType:"html", type:"POST", cache:false, timeout:1000, data:{item:"ITEM1", session:"SESSIONKEY"}});
}

// DISPLAYER
function getTools() {
$.ajax({url:"http://sub.differentdomain.com/out/sug/", dataType:"html", type:"POST", cache:false, timeout:6000, crossDomain:true, async:false, beforeSend:function() {
$("#ccont #selling-tools").html('<div class="boxset" style="width:95%; margin:20px 2%;padding:20px 0.5%; margin-bottom:0;"><img src="loader.gif" align="center" /></div>').show();
}, error:function() {
$("#ccont #selling-tools").html("");
}, data:{item:"ITEM1", session:"KEY1"}}).done(function(html) {
$("#selling-tools").html(html);
});
}

Any other suggestions on accomplishing the same outcome would also do...

Richard Dev
  • 1,110
  • 7
  • 21
  • you are using jquery maybe this can help you http://stackoverflow.com/questions/11487216/cors-with-jquery-and-xdomainrequest-in-ie8-9 – ncubica Nov 21 '13 at 03:31

1 Answers1

1

try to enable CORS in IE browser with this script , before you ajax call

if ( window.XDomainRequest ) {
    jQuery.ajaxTransport(function( s ) {
        if ( s.crossDomain && s.async ) {
            if ( s.timeout ) {
                s.xdrTimeout = s.timeout;
                delete s.timeout;
            }
            var xdr;
            return {
                send: function( _, complete ) {
                    function callback( status, statusText, responses, responseHeaders ) {
                        xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop;
                        xdr = undefined;
                        complete( status, statusText, responses, responseHeaders );
                    }
                    xdr = new XDomainRequest();
                    xdr.onload = function() {
                        callback( 200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType );
                    };
                    xdr.onerror = function() {
                        callback( 404, "Not Found" );
                    };
                    xdr.onprogress = jQuery.noop;
                    xdr.ontimeout = function() {
                        callback( 0, "timeout" );
                    };
                    xdr.timeout = s.xdrTimeout || Number.MAX_VALUE;
                    xdr.open( s.type, s.url );
                    xdr.send( ( s.hasContent && s.data ) || null );
                },
                abort: function() {
                    if ( xdr ) {
                        xdr.onerror = jQuery.noop;
                        xdr.abort();
                    }
                }
            };
        }
    });
}
AlexC
  • 9,657
  • 17
  • 64
  • 98
  • Thanks! It worked. I noticed that it didn't pass the POST info but still let the request take place. I wrote a tiny script to just switch to GET request. Thanks again. Simple answer... – Richard Dev Nov 21 '13 at 05:34