how to add a new variable to this ajax script through post

Home / Uncategorized / how to add a new variable to this ajax script through post

Question:
I need to be able to send a value from my PHP script with a variable called $topid that needs to send that id to getData.php script so i tried like
$(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);

}

});

});

But somehow it does not seem to be working all I need is the id gets sent to the getData.php script and I then get it through post like $topid = $_POST[‘topid ‘];


Answer:
if you need to sent topid to the getData change
data: {row:row}

into something like
data: {topid : topid}
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *