How to pass PHP array parameter to Javascript Function?

后端 未结 7 1118
囚心锁ツ
囚心锁ツ 2021-01-20 03:48

index.php




        
7条回答
  •  清歌不尽
    2021-01-20 04:34

    Your PHP variables only live on the server. They are completely separate from the JavaScript variables on the client. The only mechanism for passing values from the server to the client is through the contents of the web page (or through specially requested behind-the-scenes web content through AJAX).

    This means that to make your JavaScript receive PHP values, you have to write JavaScript with those values embedded inside of it. You must mix the PHP with the JavaScript at least a tiny bit to get the stuff that runs on the client to have any data from the server.

    This is how all web server-side scripting works in all languages.

    JavaScript simply cannot know what goes in your movies variable unless you stuff it full of values, in JavaScript.

    I recommend you to @levu's answer to see a good way to get your PHP variable's values into JavaScript.

提交回复
热议问题