How to write the php code in js file

前端 未结 4 471
猫巷女王i
猫巷女王i 2021-01-03 07:23

Is my program i divide the pages as a div in the first div i added this code

  

        
相关标签:
4条回答
  • 2021-01-03 07:29

    Save the file named abc.js to abc.js.php, hence server will come to know that it contains some php question, so that it will process first php content then replace the result in .js file and send to browser, By doing this the .js file will contain dynamic contents..

    0 讨论(0)
  • 2021-01-03 07:35

    In the questions code i see that the value of a JS var is being set from PHP using echo. What I need to do is the other way around. That is store values of JS vars into PHP var properties. Is it possible ? I am able to include the JS file as PHP, but not able to pass the value from JS to PHP var. PS - the values from JS come from a AJAX call, so I need to update the values regularly into PHP var..

    0 讨论(0)
  • 2021-01-03 07:36

    what you need is to call to file with php extension

    like

    <script type="text/javascript" src="/includes/slideshow.js.php"></script>
    

    and in the beginning of php file

    Header("content-type: application/x-javascript");
    

    look the example in http://www.givegoodweb.com/post/71/javascript-php

    0 讨论(0)
  • 2021-01-03 07:40

    Save the file as .php instead of .js and add

    Header("content-type: application/javascript");
    

    . at the beginning of the file. After that you will be able to link to the file as

    <script type="text/javascript" src="youfile.php"></script>
    
    0 讨论(0)
提交回复
热议问题