How do I write PHP within Javascript so that I can load file

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 …

via PHP Website Development » Search Results » ajax:

How do I write PHP within Javascript so that I can load file

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.
……………………..

You may use PHP to create a file that would be used as a JavaScript source.
or
PHP is serverside. JavaScript is clientside. So you cannot execute either language in the wrong platform.
……………………..

Maybe you are talking about AJAX?
In this example, for simplicity, I’m using jQuery JavaScript library for AJAX calls.
foo.php:
$param = $_POST[‘param’];

if ( $param == ‘header’ )
$markup = ‘

Hello

‘;
else if ($param == ‘content’)
$markup = ‘

Main div

‘;
else
$markup = ‘

‘;

return $markup;
?>bar.html:


……………………..

You don’t specify if the file is on the server or on the client. If it’s on the client side you can’t access it. The user must first upload it to your site. You can do this via a form.
If the file is on the server you can use javascript/ajax to reference the file. If you need to do some kind of processing on the file that should be done in the PHP when the file is uploaded.
Edit following clarification: You basically want to use AJAX requests to transfer data from the browser (javascript) to the server (PHP) and back. A library like this may help: http://www.modernmethod.com/sajax/. The graffiti example looks similar to what you’re talking about.

For more info: How do I write PHP within Javascript so that I can load file

PHP Website Development » Search Results » ajax

How do I write PHP within Javascript so that I can load file

Share this post:

Related Posts

Leave a Comment