Post by solushunz12 on Sept 20, 2011 23:57:14 GMT -5
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:
Syntax: [ Download ] [ Hide ] [ Select ]
//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:
Syntax: [ Download ] [ Hide ]
<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:
Syntax: [ Download ] [ Hide ] [ Select ]
<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?
Web designer india,
website designer india,
web developer india,
website developer india
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:
Syntax: [ Download ] [ Hide ] [ Select ]
//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:
Syntax: [ Download ] [ Hide ]
<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:
Syntax: [ Download ] [ Hide ] [ Select ]
<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?
Web designer india,
website designer india,
web developer india,
website developer india