• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

Loading graphic while getting form results

What would be the simplest/easiest way to show a loading graphic after hitting submit and waiting for the form results to be gathered? The results show on the same page after getting them. The amount of time to get the results varies greatly so I don't want to have to use a timer.  

Currently we're using a jquery call to do this, but mostly since it's not my strong point of a programming language - with the latest wordpress 3.0.1 and so many different plugins being required on some one site, there's apparently conflict somewhere.  

Showing a loading graphic is important for this because of the lengthy wait at times. We want the viewer to know that the results are still being gathered.

I've showed the jquery code here at EE before asking for advice, but it does seem that the code is correct. So I'm looking for an alternative to jquery so we aren't constantly running into conflicts.

Thanks for any additional options.
0
Dzynit
Asked:
Dzynit
  • 2
  • 2
1 Solution
 
bakercadCommented:
First.....your conflicts with jQuery can be avoided.  See here for details: http://api.jquery.com/jQuery.noConflict/

For the loading graphic, simply replace the container (<div>) of the search results with the graphic before the results are returned, then when the results are loaded, have them replace the graphic.

function search(){
  $('#SearchResults').html('<img src="images/loading.gif'); //replaces the content of a div with the id "SearchResults" with the loading image.
$.ajax({
   type: "POST",
   url: "search.php",
   data: "keyword=searchterm",
   success: function(data){
     $('#SearchResults').html(data); // replaces the loading image with the results
   }
 });
}
0
 
DzynitAuthor Commented:
Hopefully this doesn't make me sound really dumb, but to call your function would you use an onclick in the button? I see the word ajax, so I want to be sure I'm not confusing the languages.

Also another question - the data line:
Will that accept php and/or smarty terms ok?
0
 
bakercadCommented:
Yes, you can use "onclick" for that OR you could use a jQuery selector with an id or class of your submit button.

$.('.dosearch').click(function() { // submit button with class="dosearch"
 $('#SearchResults').html('?php echo $searchterm;?>",

An option to get the form values to send with the ajax request is to use the serialize "helper" function it will grap your form field values & you send that in the data string. http://api.jquery.com/serialize/

$.('.dosearch').click(function() { // submit button with class="dosearch"

var formValues= $('#formID').serialize(); // use id of form to get the form values.

 $('#SearchResults').html('
0
 
DzynitAuthor Commented:
I'm still unable to get your example working for me. The attached code shows the loading graphic correctly, but the results being returned when using an alert to view just say [object Object].

I've already confirmed that all variables are set correctly that you see in that code. Is there something different that needs to be done to display the real results? If it's seeing it as an object instead of html, is there an additional call that needs added to tell the jquery what is in the results?

url_form.submit(function(){
		results.hide();
		throbber.fadeIn("slow");
		results.load(seourl, {"url": url.val(), "output": "html", "ref": ref.val() }, function(){
			throbber.hide();
			results.show();
			htmltooltip.render();

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now