F
F
FullTwo2022-01-31 11:38:24
JavaScript
FullTwo, 2022-01-31 11:38:24

AJAX lifts objects up how so?

Good day in js a little teapot
But the essence of the matter is that with a new message it goes up, but it should go down I can’t understand what
Js is

$(document).ready(function()
{
var content = $("#content"),
loading = "<img style='text-align:center;' src='/images/loading.gif'>";
function chat_js()
{



    // Подгрузка новых записей
    $.ajax({
      url: "/Ajax/chat.php?",
      dataType: "html",
      type: "GET",
      data: {type: "start1", url: "/chat.asp" + location.search},
            success: function(responce){
            $("#content").after(responce);
            }
    });


}
function chat_js2()
{
// Подгрузка первых записей
    $.ajax({
      url: "/Ajax/chat.php?",
      dataType: "html",
      type: "GET",
      data: {type: "start", url: "/chat.asp" + location.search},
      beforeSend: function(){

        $("#content").append("<div class='jscroll-loading' align='center'>" + loading + "</div>");
      },
      success: function(data){

        if(data){

          content.append(data);
          content.find(".jscroll-loading:first").slideUp(700, function(){

            $(this).remove();
          });

          
        };
      }
    });


}
setInterval(function()
{
chat_js();
}, 1000);
chat_js2();

  });


PHP
if(isset($_GET["type"]) && $_GET["type"] === "start"){
$chat = $db->query("SELECT * FROM `chat` ORDER BY `id` ASC LIMIT  $start, $max");
while ($a = $chat -> fetch_assoc()) {
echo '<div id="post'.$a['id'].'">';
if($_SESSION[$id.'chlid']<$a['id']){
$_SESSION[$id.'chlid'] = $a['id'];
}

if(isset($_GET["type"]) && $_GET["type"] === "start1"){
$start = 0;
$chat = $db->query("SELECT * FROM `chat` WHERE `id` > '".$_SESSION[$id.'chlid']."' ORDER BY `id` ASC LIMIT  $start, $max");
while ($a = $chat -> fetch_assoc()) {
echo '<div id="post'.$a['id'].'">';
if($_SESSION[$id.'chlid']<$a['id']){
$_SESSION[$id.'chlid'] = $a['id'];
}


I can’t understand how this happens, even though the output is ASC, but not DESC

When the main information is loaded, everything is fine, but when they start adding a post, they go up as if php is set to DESC, not ASC

61f7aa8f33024396353535.jpeg

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question