dongyan3853 2011-05-04 11:09
浏览 37
已采纳

使用Jquery对PHP的Javascript值

My javascript file:

var ms = 3000;
$.get("curl.php", { test: ms } );

My curl.php:

$ms = $_GET("test");
echo $ms;

Firefox firebug says:

Fatal error: Function name must be a string in C:\Users\Jansu\Documents\workspace\php\curl.php on line 2

what could be the problem?

Even better would be when the javascript and php code is in the same file, so I don't have to post/get anything. Just somehow pass javascript to php.

  • 写回答

3条回答 默认 最新

  • dsvjw20866 2011-05-04 11:11
    关注

    You want [], not () (docs):

    $ms = $_GET["test"];
    

    Re your edit:

    even better would be when the javascript and php code is in the same file, so i do not have to post/get anything. just somehow pass javascript to php

    Even if they're in the same file, they're executed in completely different places. The JavaScript is executed on the client, the PHP is executed on the server. To get data from the client to the server, it has to be sent there. Ajax (the way you did it) is the primary way you do that without causing a full page refresh, so you're on the right track.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog