I'm still not getting my head around what is happening here:
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
function Trial() {
var index = 0;
var cat = [];
function getwidget() {
var id = get_name_value('salesperson');
var password = 'password';
console.log('trigger');
if (id !== "") {
var request = $.get('http://someplacesomewhere.com?test=' + id + '&password=' + password);
request.success(function (data) {
catalogue = $.parseJSON(data);
if (catalogue.status === "error") {
alert(catalogue.message);
} else {
.
.
do something
.
.
};
console.log('big');
return true;
}
});
request.error(function (data, status) {
alert("Error connecting to API:" + status);
});
}
console.log('tiny');
return false;
}
this.nextwidget = function() {
var flipflop = false;
catindex = catindex + 1;
flipflop = getwidget();
console.log(flipflop);
};
One button press for nextwidget the console output appears to be going round in an odd fashion.
trigger -> (from getwidget)
tiny -> (from getwidget but the failed path..? It shouldn't of failed and pretty sure it didn't)
false -> (in the nextwidget)
big -> (from getwidget and success)
So it appears it is running the getwidget then not doing a sync execution but async as it fails on the getwidget and then presents a false but at the same time also doing a correct run of the getwidget ????
I thought this way was sync and therefore all code should wait.... I'm really confuse how this callback and non callback works I've read a few things about it but I just want a simple do this and then do that as this is just a test code.
Thanks