I am having some problems with my code. And i thought i would share my problem with the great minds on this website to see if someone can give my brain some pointers on how to solve it.
I am working on an app (JQuery, PhoneGap) and i have a login function. The Login function sends login credentials to a webservice. So i am sending it using JQUery ajax. The webservice also contains a fetchData function that let´s my client to get some data. The webservice will check to see if i am currently logged in and that my session hasn´t timed out. If it has timeout i need to login again. And then try again. This is something the user will never see. loginUser() is a function that is used many other times in my code. So don´t want to fiddle around with it to much so i have to make alot of changes.
So here is some psuedo code:
function loginUser()
{
$.ajax(
{
....
success: function(data,status)
{
//everything worked great
return true;
},
error: function(data,status)
{
//display some user error stuff.
return false;
},
});
}
function getData()
{
$.ajax(
{
...
success: function(data,status)
{
//everything worked great. No need to login user again.
},
error: function(data,status)
{
//Opps user needs to login again and then we need to try again.
//If we have tried to getData after we tried to login (and got succeess from the loginUser() function)....report error.
//Below code will not work. But it will show you roughly what i am trying to do. It will also create an infinite loop.
if (loginUser())
{
getData();
}
},
});
}