duanhan8757 2015-11-05 08:48
浏览 36

使用jquery ajax和php填充html表

I'm stuck here for about 4 hours do alot of research and cannot fin the answer. I want to repopulate the table after updating the contents using jquery ajax and php so here is my code.

PHP script:

    if(isset($_POST['myinputval']))
    {

        $uinput = $_POST['myinputval'];
        $uinput = $mysqli->real_escape_string($uinput);


        $query = ('INSERT INTO tbltest values (" ","'.$uinput.'") ');

        if($mysqli->query($query))
        {

        } else 
            echo 'fail'. $mysqli->error;
        }

        $result= $mysqli->query("Select *from tbltest");

        if($result->num_rows>0)
        {
            while($row=$result->fetch_assoc())
            {
                $sendtojq[]=$row;
            }

            echo json_encode($sendtojq);
        }

        mysqli_close($mysqli);

Here is my script

        <script type="text/javascript">
        function ajaxsubmit()
        {
            var myinputval = $("#input1").val();

            $.ajax({url:'myphp.php', type:'post', data:{
                myinputval:myinputval
            },
            success: function(data)
            {
                alert(data);
            }
        });
        }


        </script>

This is the output when submitted

[{"ID":"1","NAME":".$newinput."},{"ID":"2","NAME":".$newinput."},{"ID":"3","NAME":".$newinput."},{"ID":"4","NAME":".$newinput."},{"ID":"5","NAME":".$newinput."},{"ID":"6","NAME":".$newinput."},{"ID":"7","NAME":"$newinput"},{"ID":"8","NAME":"twst"},{"ID":"9","NAME":"twst"},{"ID":"10","NAME":"testtt"},{"ID":"11","NAME":"testtt"},{"ID":"12","NAME":"thisssss"},{"ID":"13","NAME":"thisssss"},{"ID":"14","NAME":"tstet"},{"ID":"15","NAME":"Last"},{"ID":"16","NAME":""},{"ID":"17","NAME":"dddddddd"},{"ID":"18","NAME":"aaaaaaaaaaa"},{"ID":"19","NAME":"gggggggggggggggggggggg"},

Now what I want to do is get every single element of the array which is stored in the variable 'data' and use is at as the value of my table. Any suggestions? Thanks in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集