Expected identifier, string or … – say what?

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.

This entry was posted in Javascript. Bookmark the permalink.

21 Responses to Expected identifier, string or … – say what?

  1. Pingback: IE7 Error: Expected identifier, string or number | favrik. Waking up… » Blog Archive

  2. Sam says:

    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.

  3. kris says:

    thanks! saved a few hairs on my head!

  4. sunil says:

    Dude..!!
    Thanks, ur tips just worked awsome…I spotted the culprit in no time!!!

  5. Bryan says:

    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!

  6. jay says:

    COOL..thanks…I also saved some hair :-)

  7. Jinn Nguyen says:

    Good one

  8. Thank you so much for finding this answer – I was going crazy trying figure out where the problem was! KUDOS!

  9. Will says:

    Great, thanks.

  10. Thanks for the tip, was about to start pulling my hair out too!

  11. tom says:

    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!!

  12. Loris says:

    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…

  13. Pete says:

    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

  14. Sri says:

    Thanks sooooooooo much!!!! Saved a lot of my hair. Was almost starting to get bald ;-)

  15. Danguba says:

    TNX 1000 times. Same stupid comma in my case :D

  16. Muhaimin says:

    Thanks for this post. It really helps me one this minor problem… Now all my ajax are working

  17. Ali says:

    Thanks Mate, same issue with BIRT partials, worked in Chrome and Firefox, not in ie 6 or 7
    Much appreciated

  18. Pingback: Referrer Detector 4.2.0.1 (and the IE pain) | phoenix.heart - portfolio & more

  19. Scott says:

    Thanks! This saved me hours.

  20. sidhartha says:

    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.

  21. jalammar says:

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>