How to format data for XDomainRequest

132 Views Asked by At

I need to post data to a cross origin web service using json. This works perfectly in ie10+ but not in ie8/9.

After researching i discovered i need to use XDomainRequest but am unsure how to format the data.

For example, can i just wrap a string around my JSON object and send it or does it need to be in name value pairs like?

Im currently sending

{
"field": {
    "field": "blah",
    "field": "blah",
    "field": "blah",
    "field": "blah",
    "field": [
        "ML08BWV",
        "MJ08OJF",
        "MJ10PYO",
        "FT10EXZ",
        "SH57XUM"    
    ]}
}

I'm definitely hitting the server but the server logs suggest that im not sending any data in the request payload. :/

Edit: Javascript Code

        var xdr = new XDomainRequest(); // Use Microsoft XDR
        xdr.open('POST', URL);
        xdr.onload = function () {
            //xdr.contentType = "application/json";
            var dom = new ActiveXObject('Microsoft.XMLDOM'), JSON = $.parseJSON(xdr.responseText);

            dom.async = false;

            if (JSON == null || typeof (JSON) == 'undefined') {
                JSON = $.parseJSON(data.firstChild.textContent);
            }

            //Do something with json
        };

        xdr.onerror = function () {
            _result = false;
        };

        xdr.ontimeout = function () {
            alert('xdr ontimeout');
        };
        xdr.onprogress = function () {
            alert("XDR onprogress");
            alert("Got: " + xdr.responseText);
        };


        xdr.send("json=" + dataToSend); 

dataToSend is in the json format as posted above

0

There are 0 best solutions below