...

View Full Version : Best to Way to Pass Variables from Ajax to PHP



damik
12-09-2008, 06:14 PM
Is there a “best practice” in passing variables from Ajax to a PHP file?

Ex:
index.php


<?php

$constant = “This is my global constant I want accessible in all files.”;

?>

// ajax script
url = "extfile.php";
req.open("GET", url, true);

exitfile.php


<?php

echo $constant;

?>

This will work using sessions or if I pass $constant through the URL, but as I’m new to Ajax I’m wondering if there’s a better, more appropriate way of handling this. Thanks.

itsallkizza
12-09-2008, 10:17 PM
If I understand your needs correctly, that's fine.

Don't forget to send() your request though.

And you can grab that constant variable via .responseText (you'll need an onreadystatechange even handler to detect when you've received your response).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum