Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda