bohughes1 Posted December 13, 2010 Share Posted December 13, 2010 I’m not sure if this is a php or javascript question. I changed my yesterdays query to hopefully clarify what I am asking. I have a little program “getFileDate.php” <?php function getFileDate ($filename) { return date ("F d Y H:i:s.", filemtime($filename)); } ?> Is it possible to call this from javascript and pass a file name to it, then receive the date back? Bob Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/ Share on other sites More sharing options...
Maq Posted December 13, 2010 Share Posted December 13, 2010 You can use PHP variables in JS but not the other way around. You will need something like AJAX to have JS talk to PHP. Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1146718 Share on other sites More sharing options...
bohughes1 Posted December 19, 2010 Author Share Posted December 19, 2010 Would someone explain AJAX to me? How do I know if I have it? I used jquery.js somewhere. Does that make it AJAX? I guess my question is how do I install it? Bob Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1149239 Share on other sites More sharing options...
BlueSkyIS Posted December 19, 2010 Share Posted December 19, 2010 http://lmgtfy.com/?q=php+ajax Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1149253 Share on other sites More sharing options...
Maq Posted December 20, 2010 Share Posted December 20, 2010 Would someone explain AJAX to me? How do I know if I have it? I used jquery.js somewhere. Does that make it AJAX? I guess my question is how do I install it? Bob There are plenty of tutorials and information online. JQuery is a nice framework and one of the most popular to work with AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1149530 Share on other sites More sharing options...
gergy008 Posted December 20, 2010 Share Posted December 20, 2010 Well I would think you can get javascript variables to php by loading a php file with query strings, Set by php. Or using a form. Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1149588 Share on other sites More sharing options...
Maq Posted December 20, 2010 Share Posted December 20, 2010 Well I would think you can get javascript variables to php by loading a php file with query strings, Set by php. Or using a form. Not sure what you mean exactly. Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1149590 Share on other sites More sharing options...
gergy008 Posted December 20, 2010 Share Posted December 20, 2010 Well I would think you can get javascript variables to php by loading a php file with query strings, Set by php. Or using a form. Not sure what you mean exactly. Because I'm an idiot :-\. Let me rephrase: "I would think you could post javascript variables to php using query strings, Or you could post javascript variable to PHP through a form" But then you would have to load a complete new page. In some cases this wouldn't be a problem but It's alot easier to get PHP into javascript. <?=$variable?> Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1149591 Share on other sites More sharing options...
bohughes1 Posted December 22, 2010 Author Share Posted December 22, 2010 I'm having a real challenge with this. Would you give me an example using <?=$variable?>? I just don't see how this would communicate with a php routine. I have this little test routine http://www.treeful.com/temp/phpFile.php?param1=test but have no idea how to get its result back to javascript. And not sure how to pass param1 to it. Is this possible? Bob PS the php I would like to use is <?php function getFileDate ($filename) { if (file_exists($filename)) { return date ("F d Y H:i:s.", filemtime($filename)); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1150309 Share on other sites More sharing options...
Maq Posted December 23, 2010 Share Posted December 23, 2010 Well I would think you can get javascript variables to php by loading a php file with query strings, Set by php. Or using a form. Not sure what you mean exactly. Because I'm an idiot :-\. Let me rephrase: "I would think you could post javascript variables to php using query strings, Or you could post javascript variable to PHP through a form" But then you would have to load a complete new page. In some cases this wouldn't be a problem but It's alot easier to get PHP into javascript. =$variable?> Sure, if you reload the page you can pass values to PHP via HTTP. If you don't want to reload the page you have to use AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1150770 Share on other sites More sharing options...
bohughes1 Posted December 23, 2010 Author Share Posted December 23, 2010 I'm really feeling like an idiot now. I seem to be going in circle. What does a web site need to use AJAX. I have a test program http://www.treeful.com/temp/phptest.php. Is this AJAX? _____________________________________ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>call php test</title> <script type='text/javascript' src='jquery.js'></script> <script type='text/javascript'> function testing() { $.get( 'phpFile.php', { 'param1' : 'value' }, function(response) { } ); } </script> </head> <body onLoad="testing()"> </body> </html> _____________________________________________________________ This does not call the file 'phpFile.php'. (At least it does not echo anything) Would reloading page help? & if so where would I do it? Bob Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1150803 Share on other sites More sharing options...
Maq Posted December 23, 2010 Share Posted December 23, 2010 Take a look at this link: http://api.jquery.com/jQuery.ajax/ The link you provided is broken BTW. Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1150807 Share on other sites More sharing options...
bohughes1 Posted December 24, 2010 Author Share Posted December 24, 2010 There was a period added to end http://www.treeful.com/temp/phptest.php/ You can always just go to the directory to see my feeble attempts http://www.treeful.com/temp/ I went to your link but it's too complicated for me. I work best from examples. I think I'll give the whole idea up for the time being. Thanks for your help. Bob Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1151090 Share on other sites More sharing options...
Maq Posted December 24, 2010 Share Posted December 24, 2010 There was a period added to end http://www.treeful.com/temp/phptest.php/ You can always just go to the directory to see my feeble attempts http://www.treeful.com/temp/ I went to your link but it's too complicated for me. I work best from examples. I think I'll give the whole idea up for the time being. Thanks for your help. Bob I cannot view your source. The jquery link I gave you should provide many examples. Try and implement one and come back with your source for specific help. There are also many examples on this site for AJAX using jQuery. Quote Link to comment https://forums.phpfreaks.com/topic/221523-pass-variables-javascript-tofrom-php/#findComment-1151124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.