Code the following code that I use after doing an "Onsubmit" in the form:
function buscar(){
resul = document.getElementById('resultado');
bus=document.frmbusqueda.dato.value;
tipo=document.frmbusqueda.tipo.value;
ajax=nuevoAjax();
ajax.open("POST", "busqueda.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
resul.innerHTML = ajax.responseText
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send("busqueda="+bus);
}
Everything works perfectly, what I need is that before I get the result, add a loading image, in the code.
Any suggestions and/or help?
Thank you
Within the
ajax
jquery function there is the methodbeforeSend
where you can show a div that contains this loader that you want to showAnd in success you hide it.
Or you can also make above the ajax call the call to your div that contains the loader
And in
success
it you do the.hide()
You can use:
This solution makes it show/hide the loading id bound to a div. In this case, whenever it is an ajax or normal load request, it will be executed and you avoid having to code for each situation.