jquery - JavaScript MVC Parsing JSON -


i trying work client's api lets me retrieve group of orders in json format. able use code below display 3 alert boxes. first box shows 200 (am assuming that's html success code), blank alert box, third box says: [object object].

in chrome if use f12 key , go network preview see 3 sections, status contains body section contains orders section. there 50 orders in orders section. each order has properties such as: order_type: "pickup", etc. question how iterate through actual orders. don't know syntax reach order, , properties inside order.

my end goal loop though 50 orders, assign of order properties javascript vars , pass mvc controller insert order database. getting orders clients database via api , storing them local database. guessing using ajax call inside first .each loop post several of order properties database via call mvc controller database inserts?

thank in advance 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);            });     } }); 

based on information you've provided. first 200 alert count (number_of_orders_in_response). you're doing $.each iterating on objects properties, not orders. orders property on data object. data.orders array want.

try this:

$.ajax({   type: 'get',   url: 'https://api.customer.com/2000105850/orders.json?v=1&key=12345',   success: function (data) {                             var orders = data.orders;     var = orders.length;     while (i--) {       alert(orders[i].order_type);     }    } }); 

also, looks there pagination involved. need take consideration when writing script ensure capture pages available, not first.


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -