Upon attempting to use the JSON.stringify()
method to convert an array of strings into a JSON object for passing to a PHP script, I encountered an issue where the method did not return any meaningful output.
The code provided is the only one handling the input, without interference from any other sources.
function submitItem() {
try {
var item = [];
item.name = $('.itemText').val();
item.type = $('.itemType').val();
item.price = $('.itemPrice').val();
item.color = $('.itemColor').val();
item.desc = $('.itemDesc').val();
item.image = $('.itemImage').val();
item.giftType = $('.itemGiftType').val();
item.avail = $('.itemAvail').val();
item.giftable = $('.itemGiftable').val();
item.ranking = $('.itemRanking').val();
item.basicTrack = $('.itemBasic').val();
item.vetTrack = $('.itemVet').val();
item.month = $('.itemMonth').is(':checked');
item.hidden = $('.itemHidden').is(':checked');
item.id = $('.itemID').val();
// For confirmation purposes
var join = [];
join[0] = 'test';
join[1] = 'tset';
console.log( JSON.stringify( join ) );
console.log(item);
var JsonItem = JSON.stringify(item);
console.log( JsonItem );
} catch (err) {
console.log(err.message);
}
}
The console displays the following output:
Instead of a valid JSON string, both logs show []
. Any insights into why this might be happening would be greatly appreciated.
Thank you.