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

short answer: no.
long answer: probably not.

reason: see first sentence of your question

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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!