I am trying to send the JavaScript array to my php, but php gets empty [].
It even shows like that in my browser. I have always sent JSON and had no problem, but now have this format.
I have this example that makes no sense...it's just a code to illustrate the issue:
var blah = [];
var letters = ['a', 'b', 'c', 'd'];
for (var i = 0; i < letters.length; i++)
{
blah[letters[i]] = i;
}
Inside firebug DOM it shows as follows:
blah []
a 0
b 1
c 2
d 3
When I do
alert(blah) ------------------------------- I get emptyalert(JSON.stringify(blah)) ----- I get []alert(blah.a) ---------------------------- I get 0 So how can I pass this object to php? Thanks
Instead of an array, try using an object.
So instead of:
var blah = [];
Try
var blah = {};
Arrays are continuously numerically indexed. They do not have strings as key names.
What you want is an object {}, not an array [].
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