Solved

Question on "onLoading" with Ajax.request in Prototype

Posted on 2008-06-20
4
2,365 Views
Last Modified: 2010-04-21
I'm using the following code attached.  Basically I want to have a standard loading animation until the content is pulled down from the server and inserted into the DIV element.  Now, using actual javascript (aka not the prototype framework) i have no problems.  But I'd like to use the framework across this site, but when i use the code below sometimes my output hangs on the loading image.  Often if i click the button that calls this function twice, it'll act normally.  If i remove the onLoading code, the program functions normally.  I've been scratching my head over this and am running out of time  as I've never really used the onLoading aspect of Ajax.request before.  Any help would be appreciated
function showWindow(id) {

	var url = id+".php";

	new Ajax.Request(url, {

	  method: 'get',

	  onSuccess: function(transport) {

		   $('searchresults').innerHTML = transport.responseText;

		},

		onLoading: function(transport) {

			$('searchresults').innerHTML = "Loading...<img style=\"vertical-align:middle;\"src=\"/img/loading.gif\"/>";

		}

	});
 

}

Open in new window

0
Comment
Question by:dangereux
  • 2
  • 2
4 Comments
 
LVL 3

Author Comment

by:dangereux
ID: 21832489
just read on the prototype site onLoading is "Not guaranteed", maybe this means "not working"
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21832715
try:
function showWindow(id) { 
	 $('searchresults').innerHTML = "Loading...<img style=\"vertical-align:middle;\"src=\"/img/loading.gif\"/>";
      var url = id+".php";
      new Ajax.Request(url, {
        method: 'get',
        onSuccess: function(transport) {
               $('searchresults').innerHTML = transport.responseText;
            }
      });
 
}

Open in new window

0
 
LVL 3

Author Closing Comment

by:dangereux
ID: 31469218
didn't even think about that, thanks
0
 
LVL 82

Expert Comment

by:hielo
ID: 21832970
You are welcome!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now