MooTools Conflict

So basically I built a class that creates a datagrid for me.  It works great UNTIL I put it in a page that is using MOOTOOLS. Then it seems to add a bunch of crap to my array.  I am using this peice of code below in my grid.  The data comes back fine from my PHP page, like I said it only gets jacked up once I include the MOOTOOLS.js file.  Specifically it seems the last line is the problem.  I tried adding the json_parse library to use that instead but got the same results so it seems that mootools is doing something to my array.  Please if you can help me figure this out I will be sooo grateful.

P.S.  I only have MOOTOOLS in the page because I am using fancyupload which was written using it
objGrid.prototype.url="ajax.php?q=objGrid&criteria="+this.criteria+"&field="+this.searchField+"&sql="+this.SQL;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	this.xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
	this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
this.xmlhttp.open("GET",objGrid.prototype.url,false);
this.xmlhttp.send(null);
var aResults = eval("("+this.xmlhttp.responseText+")");

Open in new window

LVL 4
IceCodeAsked:
Who is Participating?
 
IceCodeAuthor Commented:
I figured it out.  I know eval is bad I was trying everything.  I will switch to parse but here's the deal...  Mootools extends the native Array object and adds a bunch of other stuff to it.  When you iterate over your array with a for...in type function it crawls up the prototype chain.  So, I had to modify how I iterate an array to not do that which I did with the code below.  The second line makes sure that the properties you iterate are directly present on the array object.  AND, thus you get a normal array even in the presence of Mootools or any other library that extends the native array object.
for(var i in aResults){
     if(aResults.hasOwnProperty(i)){
          //do whatever you do with the array
          alert(aResults[i]);
     }
}

Open in new window

0
 
BadotzCommented:
What array?

What is the purpose of this:

var aResults = eval("("+this.xmlhttp.responseText+")");

eval is evil - there is usually a way to refactor your code to eliminate it.
0
 
BadotzCommented:
Well, if you had POSTED your array manipulation code, it might have been easier to help you.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
IceCodeAuthor Commented:
Well if i KNEW that was the problem I would have.  Jeez.
0
 
BadotzCommented:
Read your original post:

"...so it seems that mootools is doing something to my array"

Since your original post did not reference this array in any way, I asked about it. Then you said you figured it out and posted your array manipulation code.

Apparently you knew it was the problem. Jeez.
0
 
IceCodeAuthor Commented:
Yea well I didn't know the answer was in the iteration, I had no idea that what I just did was even possible, what are you so upset about?  No points?  LOL, I guess I could have given them to you it just didn't really make sense to me to do that since your only post was a short question that didn't actually contribute to me finally finding the answer with some old fashioned research.  I could care less about points they are free anyway, just like they are for you.
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.

All Courses

From novice to tech pro — start learning today.