Why isn't IE displaying this alert()?

Posted by George Edison on Stack Overflow See other posts from Stack Overflow or by George Edison
Published on 2010-03-15T22:54:48Z Indexed on 2010/03/15 22:59 UTC
Read the original article Hit count: 195

I have the following piece of code:

// setup the AJAX request
var pageRequest = false;
if(window.XMLHttpRequest)     pageRequest = new XMLHttpRequest();
else if(window.ActiveXObject) pageRequest = new ActiveXObject("Microsoft.XMLHTTP");

// callback
pageRequest.onreadystatechange = function() {

    alert('pageRequest.readyState: ' + pageRequest.readyState
        + '\npageRequest.status: ' + pageRequest.status);
}

pageRequest.open('POST','ajax.php',true);

// q_str contains something like 'data=value...'

pageRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
pageRequest.setRequestHeader("Content-length", q_str.length);
pageRequest.setRequestHeader("Connection", "close");

pageRequest.send(q_str);

This works fine in Chrome, but IE chokes on it, spitting out an "Unspecified error." and it points to the line with the alert() in it. Why can't it display the alert?

© Stack Overflow or respective owner

Related posts about internet-explorer

Related posts about alert