Solved

Question on "onLoading" with Ajax.request in Prototype

Posted on 2008-06-20
4
2,371 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

919 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

20 Experts available now in Live!

Get 1:1 Help Now