View Full Version : how to insert php code within javascript
ainwana
05-12-2008, 05:07 AM
I need to store small data so i want to use php to write data to text file..how to insert the code within javascript-html code?My code need to be saved as .html or .php?:confused:
Strictly speaking on a technological level, PHP cannot be inserted within JavaScript, it's the other way around. Since PHP is a server side technology, it's rendering the HTML markup and JavaScript (or CSS / XML / etc) before you see the page.
Having said that, you can technically use an XMLHttpRequest (http://en.wikipedia.org/wiki/XMLHttpRequest) call to send data to a PHP script and have it perform some task, return to the current document without a reload. This is the basis for what you've no doubt heard referred to as Ajax.
Your PHP script can have various extensions, from the standard .php to .php4 / .php5 variants, to .phtml or plain .html if the web server is configured properly. Do a Google search for your web server and how to configure PHP to work with it.
Find some PHP tutorials, a PHP book or two and definitely reference the PHP Manual (http://www.php.net/manual/) to find what you want to do.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.