Is there a way I can pass a PHP variable from a PHP page to a JQuery page and back to a PHP page?
2
-
1yeah. it is called AJAX and there are tons of tutorials. You cannot pass a variable though, but only a string value. And not to the same PHP instance.Your Common Sense– Your Common Sense2010-08-06 03:24:13 +00:00Commented Aug 6, 2010 at 3:24
-
Is Jquery page generated with Jquery library dynamically?Joseph– Joseph2010-08-06 03:24:40 +00:00Commented Aug 6, 2010 at 3:24
Add a comment
|
1 Answer
Maybe I'm wrong but I believe you may be confusing things.
- Server Generates page using PHP.
- Generated page is composed of HTML, JAVASCRIPT whatever...
- Client receives page
- Received page is interpreted (JavaScript code is run)
In the end what you are asking for is possible but, by the way you put the question, I though that the above should be clarified.
How to do it?
Say you want to pass id=123 from server to client and then back.
- generate page with a tag, say
<span id="js-val">123</span> - have client read the contents of
id="js-val - client can then resend the 123 using
POSTorGETthat really depends on what you want.
Hope it helps to clear things up.
2 Comments
Alexander
You could generate the JavaScript/jQuery using PHP. It'd be a little slower, but you could directly pass strings to the code.
Frankie
@TheLifelessOne you can have Apache interpret .js files as php and use it only where you need having the whole file written as javascript and only small portions as php like
<?=date()?> for example. But that goes beyond the scope of the question.