LostSole Posted March 5, 2008 Share Posted March 5, 2008 Hi guys, I have come to a situation where I need to use AJAX to either create a new entry in $_POST, overwrite an value given the key or unset (remove it) from the array. I've written the javascript to send values to the external .php file below but I was wondering if you could help me to write the PHP to handle it....any help would be greatly appreciated! Javascript to send values to AJAXupdatePOST.php function oppositeSetVariable(elementName) { element = document.getElementById(elementName); if (element.checked == true) { // create AJAX to var newValue = 1; } else { var newValue = 0; } alert(newValue); // create AJAX to update $_POST[elementName] to equal newValue var ajaxRequest2; try{ // Opera 8.0+, Firefox, Safari ajaxRequest2 = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest2.onreadystatechange = function(){ if(ajaxRequest2.readyState == 4){ // build string var ajaxDisplay2 = document.getElementById("AJAXresultDiv"); ajaxDisplay2.innerHTML = ajaxRequest2.responseText; } } var queryString2 = "?elementName=" + elementName + "&newValue=" + newValue; ajaxRequest2.open("GET","AJAXupdatePOST.php" + queryString2,true); ajaxRequest2.send(null); } Quote Link to comment Share on other sites More sharing options...
LostSole Posted March 5, 2008 Author Share Posted March 5, 2008 Hi, I'd really appretiate some help on this, even if your not sure or have a suggestion that I could try. I simply dont know what to write in AJAXupdatePOST.php to modify the $_POST array. Do I have to send the Array to the file using the GET method, modify it and then send it back or something? Thanks for your help in advance! A VERY LostSole 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.