duanhangjian8149 2016-09-28 10:10
浏览 104

通过ajax发送php请求onclick

I know this question have been asked alot but none of the answer are related to my case ,I have a button ,onclick it should call a javascript function send it a php variable,and ajax would call a php file via post and send that vriable and the php file updates my table

so here is the onclick event first

<button class="button button6 " onclick="incrementclicks('<?php echo $id; ?>');">increment</button>

it should send a variable called $id to the javascript function

<script type="text/javascript">
    function incrementclicks(id) {
        $.ajax({
            url: "increment.php",
            data: "id=" + id,
            type: "POST"
        });
    }
</script>

and the php file increment.php (I'm 100% sure it connects to the server just fine )

<?php
     require_once 'dbconnect.php';
     $db_handle = new DBController();
     $id=$_POST["id"];
     $q="UPDATE clicks SET linkclicks = linkclicks + 1 WHERE id = '".$id."'";
     $result = mysql_query($q);
?>

it doesn't increment, I don't understand what did i do wrong here

  • 写回答

3条回答 默认 最新

  • duanfei8897 2016-09-28 10:15
    关注

    First of all you can debug your code on the php by doing

    echo $id;
    exit();
    

    My quess is that your are missing something there..

    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)