Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Jquery plugin doesn't work when loading with AJAX?

I use jquery to auto scroll blog post.. They normally works fine but it doesn't scroll or work at all when I load that page via AJAX.. The problem could be how I'm calling ajax to load the page..may be callback function issue which I'm not getting right? here is the ajax code I'm using:

  function loadme() {
   var xhttp;
   if (window.XMLHttpRequest) {
   xhttp = new XMLHttpRequest();
   } else {
   xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {

  document.getElementById("loadcontent").innerHTML = this.responseText;
  }
 };
  xhttp.open("GET", "http://xxxyyy.com/blogs/", true);
  xhttp.send();
 }

They all work but jquery post auto scroll will not work.. Is that due to callback function? I'm not sure.. Someone suggest or correct the code... Would appreciate volunteered help

Addition I did alternative callback function but that too doesn't work either..

 <div id="loadcontent"> Content to load/replace</div>

 <button onclick="loadDoc('http://xxxyyy.com/blogs', myFunction)">Browse 
 Blogs</button>

 //ajax with callback function

 function loadDoc(url, cFunction) {
 var xhttp;
 xhttp=new XMLHttpRequest();
 xhttp.onreadystatechange = function() {
 if (this.readyState == 4 && this.status == 200) {
  cFunction(this);
  }
 };
 xhttp.open("GET", url, true);
 xhttp.send();
}
function myFunction(xhttp) {
document.getElementById("loadcontent").innerHTML =
xhttp.responseText;
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Since you have tagged jquery and you also mentioned jquery in your anwser, I am providing a jquery solution.

//bind click event to the button, set an id for the button to make it just for that particular button
$(button).click(function() {
    ajaxRequest("url", loadcontent);
});


// this will be the function for ajax, with the callback as parameter
function ajaxRequest(url, callback) {
    $.ajax({
        url: url,
        method: "get",

        success: function (response) {
            callback(response);
        },

        error: function (jqXHR, exception) {
             // handle errors
        }
    });
}

// this will be passed as callback to the ajaxRequest function
//you just need to set the innerHTML and the use animate to scroll to the bottom or to whatever height you would like
function loadcontent(message) {
    $("#loadcontent").html(message);
    $("#loadcontent").animate ({ scrollTop: $("#container").prop("scrollHeight") }, 10);
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda