nadeemshafi9 Posted October 29, 2008 Share Posted October 29, 2008 Hi guys im trying to retrive my poisted vars from my form, im trying to read them in the page i post them to via AJAX but they are empty, the system works it goes throgh to the page and echos things but teh POST vars are empty. here is the JS function post_admin_form(id, adminpage) { params = "id=" + id + "&action=update"; if(adminpage == "indexpages") http.open("post", "common/AJAX/indexpages.php?id=" + id + "&action=update", true); //Send the proper header information along with the request http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = function () { if(http.readyState == 4 && http.status == 200){ var response = http.responseText; if(response) { if(adminpage == "indexpages") document.getElementById("maincontentarea").innerHTML = response; } } } http.send(params); } Quote Link to comment Share on other sites More sharing options...
aseaofflames Posted October 30, 2008 Share Posted October 30, 2008 you haven't initilized the ajax variable: var http; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari http = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted October 30, 2008 Author Share Posted October 30, 2008 i have initialised it but thanks m8 i have solved this problem now, in order for you to recive them as your $_post vars you need the following MIME http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); you have to make all your form data into a string and send it in the http.send(params); function getFormValues(fobj,valFunc) { var str = ""; var valueArr = null; var val = ""; var cmd = ""; for(var i = 0;i < fobj.elements.length;i++) { //alert(fobj.elements[i].type); switch(fobj.elements[i].type) { case "text": if(valFunc) { //use single quotes for argument so that the value of //fobj.elements[i].value is treated as a string not a literal cmd = valFunc + "(" + 'fobj.elements[i].value' + ")"; val = eval(cmd) } str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; break; case "textarea": if(valFunc) { cmd = valFunc + "(" + 'fobj.elements[i].value' + ")"; val = eval(cmd) } str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; break; case "hidden": if(valFunc) { cmd = valFunc + "(" + 'fobj.elements[i].value' + ")"; val = eval(cmd) } str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; break; case "button": if(valFunc) { cmd = valFunc + "(" + 'fobj.elements[i].value' + ")"; val = eval(cmd) } str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; break; case "file": if(valFunc) { cmd = valFunc + "(" + 'fobj.elements[i].value' + ")"; val = eval(cmd) } str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&"; str += fobj.elements[i].name + "_size=" + escape(fobj.elements[i].size) + "&"; break; case "checkbox": str += fobj.elements[i].name + "=" + escape(fobj.elements[i].checked) + "&"; break; case "select-one": str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&"; break; } } str = str.substr(0,(str.length - 1)); return str; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.