我需要能够使用名为$ topid的变量从我的PHP
脚本发送一个值,该变量需要将该id发送到getData.php脚本,所以我尝试了
$(document).ready(function(){
// Load more data
$('.load-more').click(function(){
var topid = Number($('#topid').val());
var row = Number($('#row').val());
var allcount = Number($('#all').val());
row = row + 3;
if(row <= allcount){
$("#row").val(row);
$.ajax({
url: 'getData.php',
type: 'post',
data: {row:row},
beforeSend:function(){
$(".load-more").text("Loading...");
},
success: function(response){
// Setting little delay while displaying new content
setTimeout(function() {
// appending posts after last post with class="post"
$(".post:last").after(response).show().fadeIn("slow");
var rowno = row + 3;
// checking row value is greater than allcount or not
if(rowno > allcount){
// Change the text and background
$('.load-more').text("Hide");
$('.load-more').css("background","darkorchid");
}else{
$(".load-more").text("Load more");
}
}, 2000);
}
});
}else{
$('.load-more').text("Loading...");
// Setting little delay while removing contents
setTimeout(function() {
// When row is greater than allcount then remove all class='post' element after 3 element
$('.post:nth-child(3)').nextAll('.post').remove().fadeIn("slow");
// Reset the value of row
$("#row").val(0);
// Change the text and background
$('.load-more').text("Load more");
$('.load-more').css("background","#15a9ce");
}, 2000);
}
});
});
但不知怎的,它似乎没有工作我需要的是id被发送到getData.php脚本然后我通过post来获得它像$ topid = $ _POST ['topid'];
答案 0 :(得分:0)
如果您需要将topid
发送到getData
更改
data: {row:row}
类似
data: {topid : topid}