dongliao8069 2019-01-16 17:35 采纳率: 0%
浏览 172
已采纳

如何使用ajax和jquery从我的数据库中检索记录?

I'm trying to retrieve records from my db using a button without the page refreshing. I'm not familiar with ajax and i've been having a hard time getting it to work. Here's what I have so far. any help would be appreciated, thank you

<h3>Avaiable assignments</h3><br>
<script>
 $(document).ready(function () {
$('#button1').click(function (e) {
    e.preventDefault();
    $.ajax({
        type: "GET",
        url: "getItem.php",
        dataType: "html",
        success: function (msg) {
            if (msg.success) {
            $("#responsecontainer").html(msg);
        } else {
            alert("error");
        }
    }
    });
  });
});
<br>
 <input name="button1" type="submit" id="button1" 
value="Picked" />

my getItem.php

<?php
include("connect.php");
$q = intval($_GET['q']);


if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"items");
$sql="SELECT * FROM items WHERE LIMIT 1 OFFSET 1";
$result = mysqli_query($con,$sql);


while($row = mysqli_fetch_array($result))
{
echo $row['items'];
}

mysqli_close($con);
?>
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 求一个超难的动态新增元素的 click 事件无效的解决办法。
      • ¥20 怎么修改mediawiki允许上传的文件大小?
      • ¥15 agrySEXPAYm 是毒吗
      • ¥50 Java实现注册登录实现数据库增删改查功能,数据库至少两个表
      • ¥20 求解R语言的数据分析问题
      • ¥20 求GD32F105和305解除读保护方法教程
      • ¥15 C++代码优化,复杂度太高,无法通过clang-tidy检查,用什么办法可以优=化
      • ¥15 关于跨链隐私保护方案
      • ¥15 node mongodb 根据id给子集合list添加对象 请问应该如何操作
      • ¥50 如何得到路径下的绝对路径并且回传到list上