Forum: Rails Spinoffs (closed, excessive spam) evalScripts on multiple divs update

Posted by Marcelius (Guest)
on 2008-07-02 15:26
(Received via mailing list)
Hello!

I have an ajax call generated by cakephp that should update multiple
divs like so:
new Ajax.Updater(
  document.createElement('div'),
  url_to_ajax_call,
  {asynchronous:true, evalScripts:true, requestHeaders:['X-Update',
'div1 div2']});

Now this works fine but problems occure when I add some javascript in
the response. A simple thing like this next line of code has some
unexpected behaviors:

window.myObjectDeclared.anArrayMember[3255] = someData;
alert(window.myObjectDeclared.anArrayMember.length); //returns 3255

While there really is just one element in this array. The exact same
code does work before the ajax (length is 1). Does somebody know what
the problem could be? I hope I made myself clear, it's a bit
complex :-)
Posted by Frederick Polgardy (Guest)
on 2008-07-02 15:31
(Received via mailing list)
If you assign something to the 3255th element of an array, your array
now has 3255 elements.  That's how arrays work. :-)

-Fred

On Jul 2, 2008, at 8:26 AM, Marcelius wrote:

> window.myObjectDeclared.anArrayMember[3255] = someData;
> alert(window.myObjectDeclared.anArrayMember.length); //returns 3255

--
Science answers questions; philosophy questions answers.
Posted by Marcelius (Guest)
on 2008-07-03 07:19
(Received via mailing list)
lol, I've never noticed that before... I had performance issues when
assigning 2 elements in an array, but that makes sense now with the
high numbers... I solved this using a Hash instead of an Array and now
works great!

Thanks for the response!
This topic is locked and can not be replied to.