weixin_33697898 2018-05-18 12:40 采纳率: 0%
浏览 76

Ajax POST->不传递数据

I'm a beginner so tell me if i'm doing something fundamentally wrong. I am trying to post data with ajax. The post itself works, but it is not passing any data.

<script type="text/javascript">
     $(document).ready(function(){
        $("button").click(function(){
            $.ajax({
                    type: 'POST',
                    url: 'processwifi.php',
                    data:{'postid': postid}, 
            success: function(response){
                    alert('it works');
                    }
                    });
        });
    });
</script>

And the processwifi.php

<?php
            $id = isset($_POST["postid"]);

            $link = new mysqli("127.0.0.1","***","***","secretariaat");
                    if (!$link) {
                        echo "Error: Unable to connect to MySQL." . PHP_EOL;
                        echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
                        echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
                    exit;
                    }

                $sql = "UPDATE wifi SET gebruikt='1' WHERE wifi.id='$id'";

                    if ($link->query($sql) === TRUE) {
                        echo "Update of record is '$id' successfully";
                        } else {
                            echo "Error: " . $sql . "<br>" . $conn->error;
                          }

                mysqli_close($link); 



                //Redirect result page
            //header('HTTP/1.1 301 Moved Permanently');
            //header('Location: wificode.php');
?>

Could anyone help me ?

Many thanks in advance.

  • 写回答

2条回答 默认 最新

  • weixin_33704591 2018-05-18 12:45
    关注

    You need to define the variable postid

    <script type="text/javascript">
         $(document).ready(function(){
            $("button").click(function(){
                var postid = 10; // define postid here
                $.ajax({
                        type: 'POST',
                        url: 'processwifi.php',
                        data:{'postid': postid}, 
                success: function(response){
                        alert('it works');
                        }
                        });
            });
        });
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度