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);
?>