tags:

views:

82

answers:

4

i am doing a jquery back end search of data from a DB table..until i fetch the data from the table...how do i show am image like every where its shown like searching or something like tht

+2  A: 

Have this image on your page initially...

<img id="loading" src="loading.gif" />

then with jQuery simply do this:

$(function(){
    $("#loading").hide();
});

of if it's an ajax call (which I think it is) do this:

$.ajax({
    url: 'ajax/test.html',
    success: function(data) {
        $("#loading").hide();
    }
});
hunter
might be "safer" to use "complete" instead of "success"
hunter
@Hunter: you probably want to say $(function(){$("#loading").show()}); ?;)
DCrystal
Depends how you look at it I guess. I'm thinking it's already visible on the page but you could add the .show() before the .ajax call
hunter
@Hunter: yeah, i missed this ;-)
DCrystal
+3  A: 

One more way is to use $.ajaxSetup to make show image on all of your queries:

$.ajaxSetup({   

beforeSend: function (XMLHttpRequest) {
     $("#loading").show();
},

complete: function (XMLHttpRequest, textStatus) {
 $("#loading").hide();
}
});
DCrystal
A: 

I just use code like

$(function(){
$('#id').change(function()
{
$.post('url.php',{name:$("#name").val()},function(data)
{
$("#html").html(data);
});
});
});

so i need to use the imge.show()... juts before

$("#html").html(data); rite ?

pradeep
No, before $("#html").html(data); you probably want to hide image. And before ajax call - show it(or don't do anything if your image wasn't hidden before)
DCrystal
okie..you mean to say after $('#id').change(function(){i need to show the image and before $("#html").html(data);i need to hide image.
pradeep
@pradeep: yes,exactly.
DCrystal
A: 

I have a small doubt..My project has grown big. every where .change function is used. can i write a global code like when ever change function is called..show the image until the data is loaded???

pradeep
This should be part of the question - not an answer.
David Neale
okie sorry for it....i did not know how to add it...
pradeep