Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write PHP within Javascript so that I can load files? [closed]

Tags:

javascript

php

How do I write PHP within Javascript so that I can load files? Or is there a better way? (I am loading text files from the server... so I need to use PHP to load those files. I don't know how to handle call backs in PHP but I can do it in Javascript. And from there if I can do some PHP from within the Javascript, I can solve my problem.)

thx

desired sequence:
SaveButton
LoadButton
When the "load button" is pressed, load a textfile from the server into a textbox.
When the "save button" is pressed, save the textbox text to the server.
like image 654
Kristen Martinson Avatar asked Dec 10 '22 06:12

Kristen Martinson


1 Answers

You may use PHP to create a file that would be used as a JavaScript source.

<script type="text/javascript" src="/my/js/file.php"></script>

or

<script type="text/javascript">
var str = '<?php echo 1+1;?>';
</script>

PHP is serverside. JavaScript is clientside. So you cannot execute either language in the wrong platform.

like image 65
John Giotta Avatar answered Dec 11 '22 18:12

John Giotta