Skip to content

Instantly share code, notes, and snippets.

@TimDorand
Created February 9, 2017 15:30
Show Gist options
  • Save TimDorand/789d5c9797dd30a72078d247edc0ba97 to your computer and use it in GitHub Desktop.
Save TimDorand/789d5c9797dd30a72078d247edc0ba97 to your computer and use it in GitHub Desktop.
function getTodos(){
var request = Titanium.Network.createHTTPClient();
var done=false;
request.onload = function() {
try {
if (this.readyState == 4 || !done) {
done=true;
if(this.status===200){
var content = JSON.parse(this.responseText);
// console.log(content);
var todos = content.todos;
console.log('Ajout dans la vue todos');
console.log(todos);
var todosData = _.map(todos, function(element) {
return {
properties: {
title: element.item
}
};
});
$.elementsList.sections[0].setItems(todosData);
}else{
alert('error code' + this.status);
}
}
}
catch (err) {
Titanium.API.error(err);
Titanium.UI.createAlertDialog({
message : err,
title : 'Remote Server Error',
});
}
};
request.onerror = function(e) {
Ti.API.info(e.error);
};
request.open("GET","http://10.0.2.2:8080/api/todos");
var authstr = 'Basic ' + Ti.Utils.base64encode('YsEO9fid0asz7xVcvV+rcoenFp65b+rP:');
request.setRequestHeader("Authorization", authstr);
request.send();
}
getTodos();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment