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
2010-04-27 18:01:48
might be "safer" to use "complete" instead of "success"
hunter
2010-04-27 18:05:40
@Hunter: you probably want to say $(function(){$("#loading").show()}); ?;)
DCrystal
2010-04-27 18:11:58
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
2010-04-27 18:58:24
@Hunter: yeah, i missed this ;-)
DCrystal
2010-04-27 19:21:00
+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
2010-04-27 18:08:47
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
2010-04-27 19:42:34
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
2010-04-27 19:47:50
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
2010-04-28 07:21:34
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
2010-04-30 07:03:30