I'm trying to get data from a php file with jQuery $.post method. After the ajax call i'm appending a button from php file which will onclick load more posts by removing itself, but after ajax call the jQuery is no longer working.
var result = function (str,end)
{
$.get("query.php",{ start:str, end: end },function(ajaxresult){
$(ajaxresult).appendTo(".focus");
})
}
result(4,0);
$('#loadmore').on('click', function(e){
result(8,4);
alert('delete');
e.preventDefault();
e.remove();
});
Here is my Php file code.
<?php
$start = $_GET['start'];
$end = $_GET['end'];
$con = mysqli_connect('localhost','root','binarystar','test');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"users");
$sql="SELECT * FROM post ORDER BY id DESC LIMIT $end,$start";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
{
echo "<section>";
echo "<span class='feed_username'>" . $row['username'] ."</span> ";
echo "<span class='date'>" . $row['time'] ."</span><br>";
echo "<span class='postx'>" . $row['post'] ."</span><br>";
echo "</section>";
}
echo "<button id='loadmore'>Load More Posts</button>";
mysqli_close($con);