I'm writing a Backbone + RequireJS project, and encountering the following situation:
Module A:
Backbone.Mediator.publish('ajax:fetch:in:module:b');
// I need to do something like **$.ajax(options).done()** here
Module B:
subscriptions: {
'ajax:fetch:in:module:b': fetch
},
fetch: {
$.ajax(options);
}
I've tried to hook $.ajax(options)
under a shared namespace (like cache.temp = $.ajax(options)
) in Module B, then calling cache.temp.done()
inside Module A, but it happened way before $.ajax(options)
was created so cache.temp
was simply an undefined
.
I guess one way to solve this problem is to create a deferred that delays the execution of the code before $.ajax(options)
is ready, but am not very sure whether this is something doable. Or if there are better ideas around, I am all ears.