Strange behavior with ajax call complete in JavaScript modules
Posted
by
user2598794
on Stack Overflow
See other posts from Stack Overflow
or by user2598794
Published on 2013-10-26T15:50:44Z
Indexed on
2013/10/26
15:53 UTC
Read the original article
Hit count: 227
jquery-ajax
|javascript-module
I have 3 simple modules with JavaScript code and JQuery ajax call. First module lots.js:
var Lots = (function ($) {
var self = this;
var processIsRunning;
return {
getLots: function (lotsUrl) {
var items = [];
self.processIsRunning = true;
var request = $.ajax({
url: lotsUrl,
type: 'POST',
success: function (data) {
//some code
}
});
$.when(request).done(function() {
//some code
self.processIsRunning = false;
});
},
isComplete: function () {
return !self.processIsRunning;
}
};
}(jQuery));
Module bids.js:
var Bids = (function ($) {
return {
makeBids: function (bidUrl) {
//some code
}
};
}(jQuery));
Module app.js which bundles all together:
var App = (function () {
var lots_url = null;
var bid_url = null;
var self = this;
return {
if (!self.lots_url) {
self.lots_url = lotsUrl;
}
GetLots: function (lotsUrl) {
Lots.getLots(self.lots_url);
},
MakeBids: function makeBid(bidUrl) {
//some code
var isComp = Lots.isComplete();
while (!isComp) {
isComp = Lots.isComplete();
}
Bids.makeBids(self.bid_url);
}
};
}());
But in the 'while' loop I always get 'isComplete=false'. In debug I see that 'processIsRunning' in Lots module is always true. What's the problem?
© Stack Overflow or respective owner