Jump to content

loading image during ajax process not working properly


EHTISHAM

Recommended Posts

loading image during ajax process not working properly:

 

my code smthing like this...

 

div to show content and loading image-

<div id="adS" style="float: left; width: 70%">
    <div id="loading-image" style="background-image: url('images/processing.gif'); display: none;">


    </div>
</div>

jquery code-

$(function() {


        $("#lets_search").bind('submit',function() {
          var gen = $("input[name='radGen']:checked").val();
          var mt = $('#selMtQ').val();
          var agf = $('#agf').val();
          var agt = $('#agt').val();
          var rel = $('#religQ').val();
          var cast = $('#selCstQ').val();
          $('#loading-image').show();
           $.post('adSearch.php',{gen:gen,mt:mt,agf:agf,agt:agt,rel:rel,cast:cast}, function(data){
             $("#adS").html(data);
             $('#loading-image').hide();
           });
           return false;
        });
      });

The loading image show only one time on click event.. not every time when i click search li... :(

 

Need help...

Link to comment
Share on other sites

I don't see the html associated with the jQuery which would be helpful. Anyways...

'bind' is not the preferred method for attaching events, it's 'on'. You attach the submit event on the form, not a button and there is a shortcut for doing that.

$("#id-of-form").submit(function(e) {
	
	//stop the default form submission
	e.preventDefault();

	//....rest of the code
});

If your ajax returns fast then you might miss the loading image as it did not have enough time to load before being hid again.

Don't hide the loading image and see if it displays. If it does, then you know it's working and the ajax speed is the issue. 

Edited by hansford
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.