douou8954 2019-04-11 18:21
浏览 88
已采纳

onclick funktion是如何工作的,如何获取javascript的php信息,如何获取php的javascript信息以及如何使用ajax js? [重复]

This question already has an answer here:

I try to use an onclick function. If the user clicks the html button a js function should be done. For this function I need some variables of the php code. How do I get them? If I get them I have to change them. So how do I got them (the changed variables) to php? I thought that ajax could perhaps help me. But how do I use ajax?

</div>
  • 写回答

1条回答 默认 最新

  • dongre6073 2019-04-11 18:27
    关注

    Using a library like Axios or jQuery might help, compared to using Javascript's fetch function. Here's how you might achieve that using jQuery:

    HTML

    <button onClick="handleClick()">Click me<button>
    

    Javascript

    function handleClick() {
      console.log('Clicked the button')
        $.get('path/to/script.php', function (data) {
        // It helps if the data returned in the PHP script is JSON formatted
        console.log(data)
      });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘