How to access the php file values from the External javaScript

Hi i need the help of how to access the PHP files values from the External JavaScript. I have read we should keep Header("content-type: application/x-javascript"); this line in PHP. I have done everything, if any one can explain this with Example code and please explain how to use the value in External JavaScript

How about including a PHP file which contains the javascript you wish to be able to access the PHP variables. Then in this included file pass the PHP variables to the script. You can not alter a PHP variable from javascript, but this should suffice. Here's an example:

Hi i need the help of how to access the PHP files values from the External JavaScript. I have read we should keep Header("content-type: application/x-javascript"); this line in PHP. I have done everything, if any one can explain this with Example code and please explain how to use the value in External JavaScript

Sure no problem. The solution I provided doesn't require $_GET or $_POST , nor does bodiandras'. Regarding mine, all you have to do is echo the variables from PHP into a script tag. Before you echo the </head> tag, simply output a script tag. Inside it declare some javascript variables and set their values to the values of the PHP variables like so:

Try this code. It should work. The only thing to note is PHP is server-side so it runs before the javascript which is run on the user's browser. Because of this, PHP can pass its values to JavaScript, but JavaScript cannot change the value in PHP. This is not because of a restriction, but because of the fact that the PHP will have completed execution once the JavaScript begins to run.