While working on a recent project with the excellent Prototype and Scriptaculous javascript libraries, I came across a frustrating error in IE7 (and I’m sure IE6 although I didn’t test it). The page worked beautifully in firefox but came up with “Expected identifier, string or number” on IE.
Normal debugging procedures (firebug, web developer toolbar) failed to show where my error was. To its credit, the Microsoft script debugger actually showed me the function with the error but at that time I didn’t see it as an error. After a couple of hours of hair-pulling and googling, I came across this post.
Apparently, a comma in my function was the culprit. My problem code was:
function xajax_getOptions(badgeId) { new Ajax.Request($F("absolute-url") + "/ajax/options", { method:'post', parameters: {catid: badgeId}, onSuccess: function(transport){ var response = transport.responseText; $("badgecell").innerHTML = response; getBadgeImage(); }, //onFailure: function(){ alert("an error occurred"); } }); }
Notice that I commented out the onFailure parameter without taking out the comma at the end. Firefox ignored that, IE choked.
A big thank you to Khlo for showing the way.
No related posts.
Pingback: IE7 Error: Expected identifier, string or number | favrik. Waking up… » Blog Archive
And thanks very much in turn to you for writing this post that saved me from going crazy trying to figure this out for myself.
thanks! saved a few hairs on my head!
Dude..!!
Thanks, ur tips just worked awsome…I spotted the culprit in no time!!!
I agree, thanks a TON for leading the way. I had a similar problem where my code worked in FF but not IE. Turned out my problem was using the attr “class” instead of “className” – worked in FF but not IE.
Thanks!
COOL..thanks…I also saved some hair
Good one
Thank you so much for finding this answer – I was going crazy trying figure out where the problem was! KUDOS!
Great, thanks.
Thanks for the tip, was about to start pulling my hair out too!
ahhh big thanks to bryan, had stupidly used class instead of classname and couldn’t think why i was getting the error as i didn’t have a last comma!!
Thanks a ton for the tip, it saved my hair too!
In my case the MS script debugger didn’t even show me the function with the error…
Well guys, actually the IE version is correct as any real programmer knows. The comma is a separator and by inference it follows that after a separator comes another field.
In this case, the field is NULL since the the next command is “ignore to end of line”, followed by a close container statement.
Now because the the field is NULL, which is different from an empty string then of course the program breaks and throws an error.
Firefox handles the exception nicely, which makes their browser more fault tolerant for amateur programmmers. We professionals should still observe the programming rules for accuracy and potential reuse in other environments.
Cheers
Peter
Thanks sooooooooo much!!!! Saved a lot of my hair. Was almost starting to get bald
TNX 1000 times. Same stupid comma in my case
Thanks for this post. It really helps me one this minor problem… Now all my ajax are working
Thanks Mate, same issue with BIRT partials, worked in Chrome and Firefox, not in ie 6 or 7
Much appreciated
Pingback: Referrer Detector 4.2.0.1 (and the IE pain) | phoenix.heart - portfolio & more
Thanks! This saved me hours.
boss, it is really superb. i tried for two days and after reading this, solved it in no time. same comma played a spoilsport with me.
I’ve been hunting down an error that only said “Expected identifier” only in IE (7). My research led me to this page. After some frustration, it turned out that the problem that I used a reserved word as a function name (“switch”). The error wasn’t clear and it pointed to the wrong line number.
I renamed the function and all was well again.
Hope this might save someone some time.