如何通过post添加一个新变量到这个ajax脚本
问题描述:
我需要能够从我的PHP
脚本发送一个值,名为$ topid的变量需要将该id发送到getData.php脚本,所以我尝试了像如何通过post添加一个新变量到这个ajax脚本
$(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脚本,然后通过后像$ topid = $ _POST ['topid'];
答
如果需要发送topid
到getData
变化
data: {row:row}
成类似
data: {topid : topid}
我没有说太多,但后来我试图呼应它正在传递没有值 –