的index.php <ul id="remove_row">
如何使用PHP PDO
<button type="button" name="btn_more" data-vid="<?php echo $pro_id; ?>" id="btn_more" class="btn btn-success form-control">more</button> </ul>
load_data.php
sleep(1);
require_once("config.php");
$query = $connect->prepare("SELECT * FROM county WHERE sof_similar > ".$_POST['last_video_id']." LIMIT 2");
$query->execute();
while ($row_posts = $query->fetch(PDO::FETCH_ASSOC))
{
$pro_id = $row_posts['sof_id'];
$pro_similar = $row_posts['sof_similar'];
echo " <li>
<div class='alter'>
<h1><hr /><img src='$pro_fimagelink' alt=''> <a href='$pro_downloadpage'><strong>$pro_name</strong></a> <a rel='nofollow' href='?q=$pro_name' target='_self'><small></small></a> <br />
<span>$pro_shortdescription<br />
<div class='license'>$pro_license</div>
<li id="remove_row">
<button type="button" name="btn_more" data-vid=". $pro_similar ." id="btn_more" class="btn btn-success form-control">more</button>
</li>
";
傳遞兩個變量在阿賈克斯
阿賈克斯腳本:
<script>
$(document).ready(function(){
$(document).on('click', '#btn_more', function(){
var last_video_id = $(this).data("vid");
$('#btn_more').html("Loading...");
$.ajax({
url:"/load_data.php",
method:"POST",
data:{last_video_id:last_video_id},
dataType:"text",
success:function(data)
{
if(data != '')
{
$('#remove_row').remove();
$('#load_data_table').append(data);
}
else
{
$('#btn_more').html("No Data");
}
}
});
});
});
有了這個代碼,我可以傳遞單個變量來獲得結果,但我需要2個變量才能獲得結果通過使用AJAX。我有這個博客的基本代碼:http://www.webslesson.info/2016/02/how-to-load-more-data-using-ajax-jquery.html
感謝webslesson.info給這個機會來了解AJAX。
做一些這樣的事情。 **數據:{last_video_id:last_video_id,nextVar:nextVar},** –