views:

724

answers:

1

I have a little javascript function which is attached to an onClick event of a button. It appears to work perfectly in Firefox(3.0.4), but both Opera(9.62) and IE fails to execute any other JS from the same .js file, including what normally works. The following function is the culprit:

function deleteComment(id){
   $.post("ajax/comments.php", {delete: id},
      function (reply) {
         if (reply == "true") {
            alert("Comment deleted!");
         }
      }
   );   
}

The Opera dev console says that there is a syntax error in the second line and that it expects a '}' in place of the first '{'. I assume it is the same problem for IE. Is this jQuery that fails to properly take care of the IE and Opera JS implementations or is my code faulty in some sense? I have a similar POST jQuery function in the file which works fine (when the above code is not there).

+2  A: 

Try putting the word delete in double quotes. I once had a problem with the keys needing to be strings because some browser wasn't picking them up.

Josh
remember that object keys are strings, and should in general be quoted. only for the special case where they're non-conflicting words the quotes can be omitted. unfortunately, 'non-conflicting' is a nonportable concept.
Javier
Ah, that explains why 'delete' didn't work when 'search' did.
Morten Christiansen
Thanks Javier, that explains it better.
Josh
I've learned to test in IE periodically. FF tends to be a very forgiving of errors.
Philip T.