I need help on how to refresh data when I click a button. What's it's doing is duplicating every time I click the button. Please help.
Here's my jquery code
$(document).ready(function() {
$('#button1').click(function(event) {
$.ajax({
url : 'http://localhost/api/eric_api.php?q=series',
type : 'GET',
dataType : 'json',
success : function(data) {
var table = $("#list");
$.each(data, function(idx, elem) {
table.append("<tr><td>" + elem.user + "</td></tr>");
});
},
error : function() {
alert('There was an error');
}
});
});
});
And my html code is
<?php include 'eric_api.php'; ?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="js/jquery.js"></script>
<script src="js/api_calls.js"></script>
<link rel="stylesheet" href="css/normalizer.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div>
<table id="list"></table>
</div>
<div>
<button id="button1">Get Data</button>
</div>
</body>
I'm getting the right data returned I just want to refresh data and duplicated values cascading down my page. Thanks.