On Fri, Feb 22, 2008 at 2:02 PM, Chach <[EMAIL PROTECTED]> wrote:
>
> Hi everybody,
Hello!
> for (x in siteListArray)
This is your problem right here. What that lil' "for ... in" does is
iterate over every property in the object. Arrays are objects in
Javascript, and Prototype takes advantage of that to add a ton of very
useful methods to arrays. The unfortunate side effect of this is that
using "for ... in" on a Prototype-enhanced array also iterates over
_all the extra methods_ that Prototype so considerately added to the
array. Take a look in Firebug: are there a bunch more calls to
Ajax.Request than you thought you were making?
However, _because_ you're using Prototype, you've got something at
least as cool as "for ... in," and that's each(). For example, you
could rewrite your code as follows:
siteList.each(function(site) {
var url = 'functions.php?command=numberOfErrors&site=' + site;
new Ajax.Request(url, {
// asynchronous: true is the default and can be omitted unless
you're setting it to false
onComplete: function(transport) {
$('sidebar_site_div_' + site).update(transport.responseText);
}
});
}); // <-- note that extra paren! Remember this whole function is
inside the call to each()
Give that a shot!
:Dan Dorman
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---