Reputation: 985
My code is supposed to accept a list of ID's, this list matches the scarlet-id on certain elements. My code then builds up an array with the elements attributes and the values. This is where the issues set in, when I console.log the array, it outputs in Chrome's console just fine.
But when I pass the array to JSON.stringify, or try to use it in an AJAX request, none of the data gets transmitted. (below is the output from JSON.stringify)
Here's my code.
function getScarletIDInfo(scarletIDs)
{
var scarletIDinfo = new Array();
for (var i = 0; i < scarletIDs.length; i++)
{
scarletIDinfo[scarletIDs[i]] = new Array();
$($(getSpecificSelector(scarletIDs[i]))[0].attributes).each(function()
{
scarletIDinfo[scarletIDs[i]][this.nodeName] = this.nodeValue;
});
};
console.log(scarletIDinfo);
console.log(JSON.stringify(scarletIDinfo));
return scarletIDinfo;
}
function getSpecificSelector(scarletID)
{
return "*[scarlet-id=" + scarletID + "]";
}
I'd be very grateful if somebody could point out where I'm going wrong.
Upvotes: 0
Views: 84
Reputation: 324620
You want an object, not an array.
var scarletIDingo = {};
// ...
scarletIDinfo[scarletIDs[i]] = {};
// ...
Upvotes: 4