Jquery load() and PHP variables

前端 未结 6 843
死守一世寂寞
死守一世寂寞 2020-12-03 00:29

If I load a PHP page with Jquery .load(file.php), can the included file use the php variables that were defined on the page that called the load()?

6条回答
  •  萌比男神i
    2020-12-03 00:49

    You would have to pass those variables to the loaded PHP file through the .load function.

    Example:

    $("#objectID").load("test.php", { 'choices[]': ["{$choice1}", "{$choice2}"] } );
    

    The variables defined in the current PHP file would become part of the Javascript that loads the new PHP file.

提交回复
热议问题