Hi, i need load the response of the query in the diferent elemento.innerHTML. If i do this when push a button witch function “cargar()” it works, but if i want to that this function run in ionViewDidLoad() i have this error “Unexpected end of JSON input”.
the same happens if i cut the code of “cargar()” and paste it in “ionViewDidLoad()”.
i have this code:
ionViewDidLoad() {
this.cargar();
}
cargar(){
var link = 'http://dominio.ml/api.php';
var flag = 5;
var myData = JSON.stringify({id: this.id, flag: flag});
this.http.post(link, myData)
.subscribe(data => {
this.data.response = data["_body"];
this.dato = this.data.response;
var datos = JSON.parse(this.dato);
for (var i in datos) {
var elemento = document.querySelector('#button'+i);
elemento.innerHTML = datos[i].usuario;
}
});
}