Page 1 of 1

show active

Posted: Sun Jun 19, 2011 4:18 pm
by ashwood
my ajax form goes slow sometimes and fast sometimes.. and when i open my website say the form was to run slow i dont want the user to think the textbox isn't clearing therefore the data isn't working.. and some people they click and click and i dont want 100 of the same thing in my database so i was wondering if i could add something to my ajax code that will show a image when the form is working so they no something is happening.. instead of thinking its not and clicking 100 times..

Re: show active

Posted: Sun Jun 19, 2011 4:29 pm
by Torniquet
very simply

easiest way of doing this is creating a loading image next to your submit button and having the display as hidden.
<input type="submit" class="js_button" /><img src="to/loading/image.gif" style="display:hidden" class="js_loading" />
once the submit button is clicked, show the image until the request is complete. You can also hide the submit button if you like aswell.
$('.js_button').click(function(){
    $('.js_loading').show();
    $('.js_button').hide();
    $.ajax({
    type: 'post',
    url: 'url.php',
    data: {'member' : id, 'message':message},
    success: function(){
        $('.js_button').show();
        $('.js_loading').hide();
    }
    });
});

Re: show active

Posted: Sun Jun 19, 2011 4:32 pm
by ashwood
how would i add this to my code i have.. the ajax post u have replied to before..?

Re: show active

Posted: Sun Jun 19, 2011 4:33 pm
by ashwood
ashwood wrote:how would i add this to my code i have.. the ajax post u have replied to before..?

could i put where we put the val thing could i also put $('div').show but how would i get it to go away once the request is done..? beca\use i only want it to show whilst the process is being done..

Re: show active

Posted: Sun Jun 19, 2011 4:41 pm
by ashwood
SOLVED :) thanks :)

Re: show active

Posted: Sun Jun 19, 2011 4:50 pm
by Torniquet
lol no prob.

my advise is reference all elements by a class name prefixed with something standard. i always use js_whatever. I know then that the class and element are for certain things.

the bonus is you can use multiple classes, so you can still style via class and use jquery call references.