I have this:
var testArray = [];
testArray["First"] = "First Test Data";
testArray["Second"] = "Second Test Data";
$.toJSON(testArray);
I then pass it back to server side. When I look at the object server side in handling the AJAX request all I have is “[]”.
Is there a way to do this or something similar to achieve the ability to look up data passed back from the client?
You are creating an array, but then you are using it as an object. Create an object instead, and it will be handled correctly:
or simply:
If you really want an array, then you access the items using numbers, not strings:
or simply: