Talage All American 5093 Posts user info edit post |
So, I have some AJAX code that dynamically inserts a table of data queried from a database. I assigned each row a unique id so that it can dynamically be edited and updated without having to refresh everything. Everything works fine in Firefox and, of course, it breaks in IE.
The following code blows up in IE when it gets to the part where it is setting the innerHTML of the table row equal to value. IE says it has an unknown runtime error.
function loadEditWindow(value) { alert(edit_id + 'row'); //for debugging purposes var temp = edit_id + 'row'; //table row id if(value.substring(0,7) == "success") { document.getElementById('editDiv').innerHTML = ""; document.getElementById('editDiv').style.visibility = 'hidden'; document.getElementById(temp).innerHTML = value; //error occurs here document.getElementById( edit_id + 'row').style.backgroundColor = '#9999FF'; editingData = false; }
My only theory on what might be wrong is that by dynamically inserting the entire table using the .innerHTML attribute, maybe the objects aren't being added to IE's DOM of the page and so when I try to use getElementById it can't find it. But if that was true it should tell me the object has no properties or something
Anyone got any ideas on what IE is yelling about? Or anyone know a good way of debugging javascript in IE? The built in crap isn't helping. 3/5/2008 11:55:19 AM |
qntmfred retired 40726 Posts user info edit post |
you can use the IE developer toolbar (kinda like firebug for firefox) to inspect the DOM 3/5/2008 11:59:04 AM |
DirtyMonkey All American 4269 Posts user info edit post |
IE has the IE Developer Toolbar you might find useful. It's no firebug, but it's something.
[Edited on March 5, 2008 at 12:01 PM. Reason : ^ what he said.] 3/5/2008 12:01:02 PM |
Talage All American 5093 Posts user info edit post |
sweet, that helps a ton ^, ^^
The elements are in the DOM though, so that shoots down my theory. New theory: IE sucks.
**** After lots of googling, I think I've figured it out. Apparently in IE innerHTML is read only for certain elements, including TR
In other new, Microsoft's documentation website crashes my version of IE, but works in Firefox http://msdn2.microsoft.com/en-us/library/ms533897(VS.85).aspx
[Edited on March 5, 2008 at 12:38 PM. Reason : figured it out] 3/5/2008 12:19:57 PM |
Stein All American 19842 Posts user info edit post |
1) The only reason innerHTML exists is because of IE, so have a little respect. 2) This is why one of the fundamental concepts behind AJAX is actually using the DOM. 3/5/2008 6:50:38 PM |
Talage All American 5093 Posts user info edit post |
Quote : | "1) The only reason innerHTML exists is because of IE, so have a little respect." |
Umm, so I should ignore the fact that Microsoft can't even produce a website that runs in their own browser because they came up with the innerHTML attribute?
Quote : | "2) This is why one of the fundamental concepts behind AJAX is actually using the DOM." |
What are you talking about? Expound please.
[Edited on March 6, 2008 at 12:47 AM. Reason : hat 1st one is a rhetorical question, but I would like to know what point you are making on the 2nd]3/6/2008 12:27:28 AM |
BigMan157 no u 103354 Posts user info edit post |
heh, i remember when i first ran into the read-only TR, took me a while to figure that one out too
also, he means instead of just returning and inserting straight html, you should probably be returning structured XML, parsing it, and creating elements through the DOM method, i.e. using functions like createElement and appendChild and etc.
[Edited on March 6, 2008 at 7:48 AM. Reason : document.getElementById(temp).appendChild(document.createElement('td')) and so on] 3/6/2008 7:46:41 AM |
Stein All American 19842 Posts user info edit post |
Quote : | "Umm, so I should ignore the fact that Microsoft can't even produce a website that runs in their own browser because they came up with the innerHTML attribute?" |
Their site works fine for me.
Quote : | "also, he means instead of just returning and inserting straight html, you should probably be returning structured XML, parsing it, and creating elements through the DOM method, i.e. using functions like createElement and appendChild and etc." |
Exactly. That's kind of what the X in AJA[c]X[/b] is for.3/6/2008 8:26:32 AM |
synapse play so hard 60939 Posts user info edit post |
Quote : | " Their site works fine for me." |
3/6/2008 9:48:46 AM |
Talage All American 5093 Posts user info edit post |
I see what you're saying, but its really not a requirement that you use XML. I always get a bit miffed at people who act like AJAX is this whole other language in of itself. Its not, its just an acronym made up of a bunch of stuff that already existed. The guy who came up with the acronym was using XML, so he threw that one in there.
Also, if you're sending a lot of data like I am, then parsing out the XML and creating a new element for each row and cell is going to be pretty darn slow on the user side. I can't think of any real benefit to always doing it that way, besides maybe that it follows some people's idea of a best practice. 3/6/2008 10:17:07 AM |
Stein All American 19842 Posts user info edit post |
No one here is acting like it's a whole different language.
Quote : | "I can't think of any real benefit to always doing it that way, besides maybe that it follows some people's idea of a best practice." |
You mean other than the fact that it's pretty much guaranteed to work in every browser widely in usage right now? Your very complaint is the exact benefit to doing it via DOM manipulation.3/6/2008 10:54:25 AM |
Talage All American 5093 Posts user info edit post |
Quote : | "No one here is acting like it's a whole different language." |
Quote : | "one of the fundamental concepts behind AJAX" |
Fundamental concept behind an acronym, wat? Haha, just kidding dude. But thats what I was mainly referring to when I was talking about people acting like its a language in of itself.
And you're right that it working on most browsers would be a benefit. I was dwelling a lot on the performance impact and didn't think about that. Maybe I'll actually do it your way for the next AJAX code I put together, just for kicks.3/6/2008 11:12:37 AM |