I've got a jQuery $.ajax() post and need to add an object (is it an object? string?) to the request for every item in an array. I'm lost as to the best method for doing this. I imagine it'd be best first to separate out the items from the data attribute as a variable so it's calculated before the request... but I'm not sure how to build each element. So here are some made up stuff to illustrate my point.
var items = for (var i = 0; i < $orderItems.length; i++){
'item': {
'photo': $orderItems[0].photo,
'option': $orderItems[0].option,
'cost': $orderItems[0].cost
}
},
request = $.ajax ({
type: 'POST',
dataType: 'json',
data: {
'firstName': $firstNameVal,
'lastName': $lastNameVal,
'email': $emailVal,
'phone': $numberVal,
'address': {
'street': $streetVal,
'city': $cityVal,
'state': $stateVal,
'zip': $zipVal
},
'price': $orderTotal,
'items': items
}
});