Jump to content

AJAX to Manipulate Superglobal Arrays


LostSole

Recommended Posts

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);  
}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.