Struggling to retrieve data from my API endpoint using AJAX. During the iteration of the JSON object to populate my JavaScript array, I seem to be overlooking some values. Here's a breakdown:
API data:
HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"sales_rev_quota": [],
"sales_revi": [
{
"month": 1,
"sum": 123000
},
{
"month": 2,
"sum": 132000
}
],
Below is my code snippet for extracting data into a JavaScript array:
endpoint = 'api/chart/data'
$.ajax({
type: "GET",
url: endpoint,
success: function(data){
window.revi_sum = []
window.revi_month = []
window.sales_revi = data.sales_revi
for(i=0 ; i < sales_revi.length ; i++){
revi_sum.push(sales_revi[i].sum)
revi_month.push(moment().month(sales_revi[i].month - 1).format("MMMM"))
console.log(revi_month)
console.log(revi_sum)
}
},
error: function(error_data){
console.log('error')
console.log(error_data)
}
})
Check out the console output:
["January"]
0: "January"
length: 1
__proto__: Array(0)
(index):112
[123000]
0: 123000
length: 1
__proto__: Array(0)