douweng1904 2013-06-04 16:13
浏览 46
已采纳

如何在Js按钮单击时使用Javascript变量执行PHP脚本? [关闭]

I would like to run a PHP segment of code with veriables from a Javascript text field while using that veriable in the PHP function. All of that should be executed with a Javascript button click.

[Js Text] --> Js button click --> veriable --> PHP (MySQL DB)

An attached sample code would be grand.

Thanks.

  • 写回答

3条回答 默认 最新

  • dongyipa0028 2013-06-04 16:17
    关注

    KEYWORD: AJAX (Asynchronous JavaScript and XML). With jQuery you can perform a POST request to a PHP script and receive a response.

    $.post("test.php", { name: "John", time: "2pm" })
        .done(function(data) {
            alert("Data Loaded: " + data);
        });
    

    See: http://api.jquery.com/jQuery.post/

    PS: In your PHP you can use: $_POST['name']/$_POST['time'] to request these variables.

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

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作