Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

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