Answer the question
In order to leave comments, you need to log in
Is it possible to load content using AJAX?
I bring to the site the latest entries from the group in VK in this way:
<?php
$wall = file_get_contents("http://api.vk.com/method/wall.get?v=5.52&filter=others&domain=***&count=10");
$wall = json_decode($wall);
$wall = $wall->response->items;
for ($i = 0; $i < count($wall); $i++) {
$user = file_get_contents("http://api.vk.com/method/users.get?v=5.52&user_ids=".$wall[$i]->from_id."&fields=photo_100");
$user = json_decode($user);
$user = $user->response;
echo "<img src='".$user[0]->photo_100."' />".$user[0]->first_name." ".$user[0]->last_name;
echo "<p><b>".($i + 1)."</b>. <i>".$wall[$i]->text."</i><br /><span>".date("Y-m-d H:i:s", $wall[$i]->date)."</span></p>";
}
?>
Answer the question
In order to leave comments, you need to log in
Thanks Ingush Archakov , I did it like this, while everything works as it should, the only thing I need to do at the end of the script is not offset ++ but add each click by 10, I don’t know the language, I can’t understand how this is done correctly)
var offset = 0;
$(document).ready(function(){
$('a.test').click(function(){
$.ajax({
url: "test.php",
method: "GET",
cache: false,
data:"offset=" + offset,
success:function(data){
console.log(data);
$("body").append(data);
}
})
offset++;
console.log(offset);
});
});
var offset = 10;
$(document).ready(function(){
$('a.test').click(function(){
$.ajax({
url: "test.php",
method: "GET",
cache: false,
data:"offset=" + offset,
success:function(data){
console.log(data);
$("body").append(data);
}
})
offset = offset + 10;
console.log(offset);
});
});
<?php
$wall = file_get_contents("http://api.vk.com/method/wall.get?v=5.52&filter=others&domain=****&count=10&offset=".$_GET["offset"]);
$wall = json_decode($wall);
$wall = $wall->response->items;
for ($i = 0; $i < count($wall); $i++) {
$user = file_get_contents("http://api.vk.com/method/users.get?v=5.52&user_ids=".$wall[$i]->from_id."&fields=photo_100");
$user = json_decode($user);
$user = $user->response;
echo "<img src='".$user[0]->photo_100."' />".$user[0]->first_name." ".$user[0]->last_name;
echo "<p><b>".($i + 1)."</b>. <i>".$wall[$i]->text."</i><br /><span>".date("Y-m-d H:i:s", $wall[$i]->date)."</span></p>";
?>
It is possible and very simple. Using offset and count in the request, send these parameters via AJAX.
Initially, use a variable that stores A strings and B offsets. And when a request for your script comes, get parameters via $_GET and insert them into these variables.
And in JS, on each call, add +N times (n is the number of new entries).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question