JavaScript in IE11 gives me script error 1003

I have a site with an accordion and some javascript. In Firefox, everything works as it should, but in IE11 I get an error

SCRIPT1003: Expected ':'

I narrowed it down to this piece of code in the .js file:

var nmArray = new Array(); function saveplayers() { var x; for (x=0;x<32;x++) { var y = "i"+eval(x+1); nmArray[x]=document.getElementById(y).value; } var request = $.ajax({ type: "POST", url: "savep.php", data: ({ nmArray }), cache: false }); } 

The error says that there should be a colon after nmArray in ({ nmAray })

If I output this function, my site works again. For debugging, I deleted my HTML, and I don’t even call this function. I just included the .js file.

+5
source share
1 answer

The syntax ({nmArray}) in a browser that supports ES6 is a shortcut to {nmArray: nmArray} . IE11 does not support this function (based on the error you received), so you will have to rewrite it as:

 data: ({ nmArray: nmArray }), 

See an example here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_6

note that in this case you can omit the wrapping ()

 data: { nmArray: nmArray }, 
+4
source

All Articles