June 15, 2010
How to import php with javascript?
Question by dcp3450
I know JavaScript is client side and PHP is server-side. I also know this is an odd question. However, the CMS editor I’m using will not allow php to be stored to the database (it’s the same editor used by Dupral). I can store JavaScript though.
Can I import a php file with JavaScript. Or rather read the php file, store the content in a variable then out put the content to the screen?
Answer by zaphod
Answer by Starx
Even though you manage to store PHP codes inside javascripts like document.write("<? echo $myvar; ?>");
the portion <? echo $myvar; ?>
will simply display as text because only server can parse this type of codes.
However, through AJAX, you can execute the PHP code through Javascript and import the results to display to the user.