It's all in the title, I would like to generate a CSV file from the JSON objet get from this Ajax request,
The JSON I get represent all the recordings from a form :
I already have something that work for one field value a a single recording (the 0 here) :
<!DOCTYPE html>
<meta charset="utf-8"/>
<html>
<head>
<title>This is Website Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js" type="text/javascript"></script>
<script src="../FileSaver.js"></script>
<script>
var formId = 566091
// Définition des paramètres de la requête HTTP
var settings = {
"async": true,
"crossDomain": true,
"url": "https://www.kizeoforms.com/rest/v3/forms/"+formId+"/data/readnew",
"method": "GET",
"headers": {
"content-type": "application/json",
"Authorization": "******",
}
}
// Envoi de la requête et affichage en console de la réponse
$.ajax(settings).done(function (response) {
console.log(response);
var ssa3 = [];
for (var i = 0 ; i <= response.data.length; i++) {
ssa3.push(response.data[i].fields.ssa_3_a_22h00.value);
}
//var ssa3 = response.data[0].fields.ssa_3_a_22h00.value;
var blob = new Blob([ssa3], {type: "application/csv;charset=utf-8"});
saveAs(blob, "ssa3.csv");
});
</script>
</head>
</html>
I would now like to have this field value for all the recordings, I have tried to push it into a table but console tells me "i is undefined"
$.ajax(settings).done(function (response) {
console.log(response);
var ssa3 = [];
for (var i = 0 ; i <= response.data.length; i++) {
ssa3.push(response.data[i].fields.ssa_3_a_22h00.value);
}
var blob = new Blob([ssa3], {type: "application/csv;charset=utf-8"});
saveAs(blob, "ssa3.csv");
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…