xhr IE send error

I'm trying to use XHR POST, and all is working well except, well, in IE :(

IE doesn't like this line (Invalid Argument):


here's the whole snippet:

var data = ['perfs='+ navigationStart,  domLoading  ];

sendRequest('request.php', data);
            function sendRequest(url, postData) {
                        var req = createXMLHTTPObject();
                        if (!req) return;
                        var method = (postData) ? "POST" : "GET";
                        if (postData)
                                req.onreadystatechange = function () {
                                if (req.readyState != 4) return;
                                if (req.status != 200 && req.status != 304) {
                        if (req.readyState == 4) return;


                function createXMLHTTPObject() {
                        var xmlhttp = false;
                        var XMLHttpFactories = [
                                function () {return new XMLHttpRequest()},
                                function () {return new ActiveXObject("Msxml2.XMLHTTP")},
                                function () {return new ActiveXObject("Msxml3.XMLHTTP")},
                                function () {return new ActiveXObject("Microsoft.XMLHTTP")}
                        var len = XMLHttpFactories.length;
                        for (var i=0;i<len;i++) {
                                try { xmlhttp = XMLHttpFactories[i]();}
                                catch (e) {continue;}
                        return xmlhttp;

Open in new window

LVL 25
Kyle HamiltonData ScientistAsked:
Who is Participating?
Robert SchuttConnect With a Mentor Software EngineerCommented:
To convert your data array to the type 'application/x-www-form-urlencoded' (which is what you're sending) you could (as a first step) replace line 20 by:

Open in new window

Robert SchuttSoftware EngineerCommented:
By the way, if it's working OK when you use XMLHttpRequest (in browsers like FireFox and Chrome presumably), then of course by all means, only use the 'old school conversion' to a string when using one of the ActiveX objects (in IE).
Kyle HamiltonData ScientistAuthor Commented:
Awesome - thank you. Did the trick!

I ended up doing this:


which gives me the standard comma, which I later use to explode the string in php.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.