I have a site with an accordion and some javascript. In Firefox everything is working as it should, but in IE11 I get the error
SCRIPT1003: Expected ':'
I narrowed it down to this piece of code in my .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 complains there should be a colon after nmArray in ({ nmAray })
If I take this function out, my site works again. For debugging I stripped down my HTML, and I'm not even calling this function. I just included the .js file.
The syntax ({nmArray})
in a browser that supports ES6 is a shortcut for {nmArray: nmArray}
. IE11 doesn't support this feature (based on the error you're receiving), so you'll have to rewrite it as:
data: ({ nmArray: nmArray }),
See here for an example: 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 },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With