Ajax: http_request.send problem

Hi, It's getting a usual weekly posting habbit with my coding problems. I usually don't go into Ajax because I'm really not good at it but I have to following problem, I'd like to "Post" some values with Ajax/JS but it does not work.


function update_form(myForm) {
http_request = false;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxm12.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Error create XMLHTTP instance');
return false;
}

theForm = document.getElementById('theform');
theStr = '';
for (i=0; i < theForm.elements.length; i++) {
ele = theForm.elements[i];
theStr += ele.name + ' : ' + ele.value + "n";
}

url = "administration_ajax.php?update=ajax_adm_centerboxes.php";
http_request.onreadystatechange = update_form2;

http_request.open('POST', url, true);

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

http_request.send(theStr);
}

function update_form2() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
document.getElementById('status').innerHTML = http_request.responseText;
} else {
alert('Have problems loading new page');
}
}
}

Everything works fine, file is called like it should, but the "POST" data does not arrive. I've tried with "GET" and it arrives good, but i cannot use it, because the URL length might exceed. therefor I really need to find out how to get this to work, and am sure someone knows the answer out here on 9r.

Leave a Reply




Created by DesignForWeb company. All rights reserved © 2007-2010. Check also the iPhone / iPad developers blog
Disclaimer
The materials collected in this blog were taken from open access sources. We try our best to preserve the copyrights of original authors and clearly state the authorship as well as link to original source website where it's possible. Please leave your comment if you feel offended by any post or if you dispose of any information about breach of copyright law in this blog. We will do our best to resolve the situation immediately.