Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCRIPT1028: Expected identifier, string or number

I'm running a plugin that displays an events calendar. It works great in all browsers except in IE compatibility mode. When that option is checked, the calendar disappears. I believe its a JS error.

IE Debugger Error:

element.qtip({
    content: {
    text: event.description,
    title: {
    text: 'Description',
    }
  },
position: {
    at: 'top right',
    adjust: {
    x: 0, y: 30
   },
},

In my plugin editor this is the code:

element.qtip({
  content: {
  text: event.description,
  title: {
  text: '<?php _e('Description', 'event_espresso'); ?>',
  }
},
position: {
   at: 'top right',
   adjust: {
   x: 0, y: 30
  },
},

I'm not great at debugging so any help would be appreciated.

If it helps, here is the page: http://www.mbausa.org/calendar/

like image 741
user1712040 Avatar asked Oct 01 '12 14:10

user1712040


3 Answers

Internet Explorer have troubles with trailing commas in objects and arrays;

title: {
    text: 'Description', //<--
}

You probably want:

title: {
    text: 'Description'
}
like image 197
Björn Avatar answered Nov 20 '22 05:11

Björn


There are 2 common causes for this error. Either having a trailing comma when inappropriate, or using a JavaScript reserved word. In your case, you have 2 unnecessary commas. Below is the correct code snippet, with comments where I removed the commas.

element.qtip({
  content: {
  text: event.description,
  title: {
    text: '<?php _e('Description', 'event_espresso'); ?>' // Removed Comma
  }
},
position: {
  at: 'top right',
  adjust: {
    x: 0, y: 30
  } // Removed Comma
},

I actually did a blog post (and video) explaining the error and showing examples and fixes. It can be found here: http://mikemclin.net/fixing-error-script1028-expected-identifier-string-or-number/

like image 28
Mike McLin Avatar answered Nov 20 '22 05:11

Mike McLin


Old version of IE doesn't support mal-formated JSON String.

You should never put a comma ',' separator when no braces '[', accolades '{' or new object properties come after.

Try :

position: {
at: 'top right',
adjust: {
   x: 0, y: 30
  } // <-- no comma here
},

instead of :

position: {
at: 'top right',
adjust: {
   x: 0, y: 30
  }, // <-- comma here
},
like image 8
Pierre Avatar answered Nov 20 '22 03:11

Pierre