Jump to content

Recommended Posts

Hello folks, hope everyone is having a great Sunday.  Well I'm trying to use AJAX as the topic suggests, to change the value of a PHP variable with an onclick event. The variable ($set_stream_limit) is assigned a default value of 4 and I'm trying to change this value to 11 with the onclick event. So the idea is just to simply post some data to the server, onto the same file (member.php) that contains the variable and the onclick link. I'm not trying to get any response text back from the server. So somewhere on member.php page, I initialize the variable like so:

 

//Define the stream limit variabe.

if(isset($_POST["send_data"])) { 

$set_stream_limit = $_POST["send_data"];

} else {$set_stream_limit = 4;} 

echo $set_stream_limit;

 

and somewhere down the page, I include the onclick event:

<a href ="javascript:;"  onclick = "set_stream_limit('member.php' , 11);"> Set Limit </a>	 	 

 

Here is the AJAX code that's supposed to perform the magic:

 

<script type="text/javascript">  
            
function set_stream_limit(url, data_to_send){

	var page_request = false;

	if (window.XMLHttpRequest) page_request = new XMLHttpRequest();

	else if (window.ActiveXObject) page_request = new ActiveXObject("Microsoft.XMLHttp");

	else return false;

	if (data_to_send) {

		var send_data = 'send_data=' + data_to_send;

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

		pageRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		pageRequest.send(send_data);

	} else {

	pageRequest.open('GET, url, true);

	pageRequest.send(null);


}

</script>

 

Well I expect the printed value of 4 to change to 11 when I click on the link but it doesn't.  Am I making any sense at all with this approach? If so, where am I going wrong?

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.