I have a problem with this api.
this is in html
<div id="summary"></div>
this is in JS
var consuKey = "ck_b04aa6f288ee9a5495dee9c5db0a6b136350e005";
var consuSecr = "cs_1f98d389d0f9b47cd3200023864cf9b7cba50574";
function callurl() {
$.ajax({
url: 'https://test.juand.org/wc-api/v2/reports/sales?',
data:{
filter: {period: "last_week"},
consumer_key: consuKey,
consumer_secret: consuSecr
},
type: "GET",
dataType: "json"
})
.done(function(data){
JsonpCallback(data.reports)
})
.fail(function(data){
console.log("no");
})
}
function JsonpCallback(json) {
for (var i = 0; i < json.length; i++) {
$('#summary').append('<b>Descripción:</b> ' + json[i].total_sales + '<br />');
$('#summary').append('<hr />');
}
}
callurl();
I have the following error
Uncaught TypeError: Cannot read property 'length' of undefined
at JsonpCallback (VM2284:68)
at Object.<anonymous> (VM2284:60)
at fire (VM2283 jquery-2.2.4.js:3187)
at Object.fireWith [as resolveWith] (VM2283 jquery-2.2.4.js:3317)
at done (VM2283 jquery-2.2.4.js:8757)
at XMLHttpRequest.<anonymous> (VM2283 jquery-2.2.4.js:9123)
the idea is that of the result of the json ( total_sales ) but I still do not understand why I get the error, if I call JsonpCallback (data.reports) if I use
JsonpCallback (data.sales)
does not give any results ..
You can help me find a request, Thanks !!
can see my code here