dpruwm6206 2013-08-03 04:20
浏览 34
已采纳

将Javascript变量导入php而不使用post [duplicate]

This question already has an answer here:

Hi i have made a php function that has to be called from script tag since the value is generated from javascript. In short i have to execute php function dynamically in one page itself. The think i can achieve is that i can call a function with static parameters such as

$(".countryoptions").click(function(){
    console.log($(this).val());
    console.log(<?php echo json_encode(getRegions(NULL,NULL));?>);
    console.log(<?php echo json_encode(getRegions(NULL,"$(this).val()"));?>);
});

The first two values are been printed as expected but the third makes me sad, values are been passed as string ("$(this).val()") itself not the value. It may be stupid but is there any way to encounter this problem without POST request.

Thanks in advance.

</div>
  • 写回答

1条回答 默认 最新

  • duandi8852752 2013-08-03 04:25
    关注

    Javascript is a client-side language, and PHP is server-side. PHP has no control over the page elements once the page has been loaded. What you're trying to do now is echo the values in your console using <?php tags. This will not work.

    If you want to access the PHP variables in your JS code, you can use a GET request or even POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable