Trouble submitting POST ajax request on Chrome: INVALID_STATE_ERR:DOM Exception 11

L

laredotornado

Hi,

I'm trying to submit a framework-independent post ajax request, but
running into some errors on Google Chrome (Firefox and IE seem to work
fine). Specifically, I receive the error, "Uncaught Error:
INVALID_STATE_ERR: DOM Exception 11" on this line

ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");

Here is how I'm creating the AJAX request ...

function getXmlHttpRequest() {
var ajaxRequest; // The variable that makes Ajax possible!
try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
return ajaxRequest;
}

Any ideas what I'm doing wrong on Chrome? Below is the method the
above line is taken from.

function save() {
var ajaxRequest = getXmlHttpRequest();

// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
alert(ajaxRequest.responseText);
}
}

// get the params
var params = serialize(document.getElementById('main'));
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
ajaxRequest.open("POST", "save", true);
ajaxRequest.send(params);
}

I'm on Win XP. Thanks, - Dave
 
M

Martin Honnen

laredotornado said:
I'm trying to submit a framework-independent post ajax request, but
running into some errors on Google Chrome (Firefox and IE seem to work
fine). Specifically, I receive the error, "Uncaught Error:
INVALID_STATE_ERR: DOM Exception 11" on this line

ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
ajaxRequest.open("POST", "save", true);
ajaxRequest.send(params);
}

First call the open method, then set any request headers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top