We help IT Professionals succeed at work.
Get Started

xhr IE send error

Kyle Hamilton
on
879 Views
Last Modified: 2012-08-13
I'm trying to use XHR POST, and all is working well except, well, in IE :(

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

xhr.send(data);

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";
                        req.open(method,url,true);
                        if (postData)
                                req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
                                req.onreadystatechange = function () {
                                if (req.readyState != 4) return;
                                if (req.status != 200 && req.status != 304) {
                                        return;
                                }
                                window.log(req.responseText);
                        }
                        if (req.readyState == 4) return;
                        req.send(postData);
                }

                

                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;}
                                break;
                        }
                        return xmlhttp;
                }

Open in new window

Comment
Watch Question
Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE