dongwen2162 2014-03-18 13:12
浏览 35
已采纳

通过AJAX调用将PHP变量转换为jquery脚本文件

So basically i have two files. 1 is my php file and it creates tables with some variables when it's called, and second file is jquery script file that makes that call. My script file:

$.ajax({
                type: 'POST',
                data: ({p:2,ank : ankieta,wybrane:wybrane}),
                url: 'zestawienia_db.php',
                success: function(data) {

                     $('#results').html(data);
  }
        });

and it works fine by printing my results. My php file is echoing data that should be printed in my results div. Question is how to get some PHP data variables and be able to use them in my jquery file without actually echoing them ??

  • 写回答

4条回答 默认 最新

  • dongmu4591 2014-03-18 13:20
    关注

    Like i said in my comment to your question, a way to do that is by echoing the variables on a script tag, so you can access in javascript.

    <script>
    var PHPVariables;
    PHPVariables.VariableName1 = '<?=$phpVariableName1?>';
    PHPVariables.VariableName2 = '<?=$phpVariableName2?>';
    PHPVariables.VariableName3 = '<?=$phpVariableName2?>';
    </script>
    

    And you could use those values accessing PHPVariables.VariableName1 on the javascript.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置