I am trying to work with a client's API that lets me retrieve a group of orders in json format. I am able to use the code below which will display three alert boxes. The first box shows 200 (am assuming that's the html success code), then I get a blank alert box, then the third box says: [object Object].
In Chrome if I use the F12 key and go to Network Preview I see three sections, the Status which contains a Body section which contains the Orders section. There are 50 orders in the Orders section. Each order has properties such as: order_type: "Pickup", etc. My question is how do I iterate through the actual orders. I don't know the syntax to reach the order, and the properties inside the order.
My end goal is to loop though all 50 orders, assign some of the order properties to JavaScript vars and then pass that into an MVC controller which will insert that order into my database. Basically getting orders from the Clients database via their API and storing them into my local database. I am guessing that I will be using a another ajax call from inside the for first .each loop to post several of the order properties into my database via a call to an MVC controller that will do the database inserts?
Thank you in advance for any help.
$.ajax({
type: 'GET',
url: 'https://api.customer.com/2000105850/orders.json?v=1&key=12345',
success: function (data) {
$.each(data, function (index, element) {
alert(element);
});
}
});