I'm using ajax to post to the server, with the following code:
$.post( "/api/server_login.php", { variable_1, variable_2 }, function( json ) {...
Where the array in the middle is short-form for:
$.post( "/api/server_login.php", { variable_1:variable_1, variable_2:variable_2 }, function( json ) {...
In other words, using the variable name as the key AND the variable contents as the value.
This short-form works in all browsers except Internet Explorer.
Did I make this short-form up, with it just happening to be working in all the other browsers? Or is this something I can fix in Internet Explorer somehow?
Tried looking for resources on this but couldn't find anyone else using this short-hand for associative arrays in Javascript!
This is a new feature in ES6/ES2015, where you can use a variable name for both the key and value of an object. You can read more about it here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer
Notice the browser compatibility at the bottom of the page and that IE doesn't have support for 'Shorthand property names'.
You want to say object, not array (array => [0,1,2]
, object => { a: 1, b: 2 }
).
The shorthand syntax you want to use is a part of ES2015 new features, implemented by the last versions of Firefox and Chrome, but not IE.
If you want to write your code using new javascript syntax you need to use a transpiler that will transform your code to work with IE and old browser versions.