Please refer the below called function in our project.
var obj; // this will modified in A() function
function c()
{
A();
B(obj);
}
function A()
{
for(i=0;i < object.length; i++)
{
if(object.data.toString()=="remote data")
processRemoteData();
else
processData();
}
}
function processRemoteData()
{
$.ajax({
url://remote url
success:function(data)
{
// set this remote data in some object that will be passed in b function
}
});
}
function processData()
{
//process data
}
am going to pass the obj (object) in B() function which will be modified in A() function or which will be set in A() function. but A() function noting returned.
i want to wait A() function to fetch either remote data or normal data until B() function never going to start. because based on the object modified in A() function am going to process in B() function.
but in my scenario A() function never waits until its fetch the data from remote URL, it starts B() function immediately.
i have tried like that
$.when(A()).done(function()
{
B();
});
this also not working and then i approached $.deferred that means
function A()
{
var def= $.deferred();
//process
return def.promise();
}
but this kind of approach also not working fine for me since A() function never waits until it completes the callback function and then start B()
Thanks,
Siva