Javascript 使用ajax在单击按钮时调用php函数,并通过参数进行解析

Javascript 使用ajax在单击按钮时调用php函数,并通过参数进行解析,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我想用ajax解析参数。。。有可能吗?如果是的话,我该怎么做呢 HTML/JS <script> function myAjax() { $.ajax({ type: "POST", url: '/ajax.php', data:{action:'follow'}, success: function() { console.log("called");

我想用ajax解析参数。。。有可能吗?如果是的话,我该怎么做呢

HTML/JS

<script>
    function myAjax() {
       $.ajax({
          type: "POST",
          url: '/ajax.php',
          data:{action:'follow'},
          success: function() {
             console.log("called");
          }
      });
    }
</script>
<button type='button' name='follow' id='follow' onclick='myAjax()'>Follow @<?php echo $profile ?></button>
这样使用:

  myAjax({action:" follow",id:1234});
这样使用:

  myAjax({action:" follow",id:1234});

你的代码有错误吗!!那么,你的代码不起作用了?您是否在浏览器控制台上收到任何错误、PHP警告/错误?代码中没有错误,我想知道如何将变量发送到ajax.PHP以用作parameter@Natelangner无论你在
数据
对象中输入什么,都会进入php脚本。@natelagner我不知道你的问题到底是什么,但是你可以看到$\u的帖子现在在
ajax.php
文件上执行['action']。如果您的意思是在控制台上看不到
ajax.php
结果,只需将success..更改为
success:function(result){console.log(result);}
在您提交的代码中是否有错误!!那么,您的代码不起作用了?是否有错误、PHP警告/错误或在浏览器控制台中?代码中没有错误,我想知道如何将变量发送到ajax.PHP以用作parameter@Natelangner无论您在
数据中输入什么
对象都将通过php脚本。@Natelagner我不知道你的问题到底是什么,但你现在可以在
ajax.php
文件上看到“$_POST['action']”。如果你的意思是你不能在你的控制台上看到
ajax.php
结果,只需将success.更改为
success:function(result){console.log(result)}
  myAjax({action:" follow",id:1234});