Syntax analyzer mode... STOP!
function ajaxCall(url, targetDiv) {
dfd = new $.Deferred(); // <-- Wait, a global variable?
Second ajaxCall(...)
is setting a different Deferred
instance, and first deferred won't never be resolved (you're setting the same variable twice, so .resolve(...)
is called on the second ajaxCall(...)
function call only and you're not resolving the first deferred object because it's gone!).
Solution:
function ajaxCall(url, targetDiv) {
var dfd = new $.Deferred(); // <-- Oh! A local variable... :)
Do you want a good suggestion? Always declare variables with var
, since variables declared in a function scope will be added to the function instance, instead of window
object:
// Both sentences are equivalent in a function scope (or in the global scope)
a = "hello";
window.a = "hello";