I am accessing my website using its REST API service available to me that allows the me to first authenticate and then use that authentication's session returned value to carry out further API calls. I can access it fine and properly without any issues. The session times out after an hour. Lets say I would like to make an API call after an hour, I would like to reauthenticate and continue with an AJAX call that was happening in the first place. Could you suggest me on how I can redo an AJAX call that would first authenticate if the session has timed out and then continue with the original AJAX call that was there in the first place?
$.ajax({
type: "GET",
dataType: "json",
url: "url",
cache: false,
async: false,
success: function (data) {
alert(data);
},
error: function(xhr, textStatus, errorThrown) {
//$.ajax(this);
//return;
},
statusCode: {
403: function() {
var session = retryLogin();
if(session !== "")
{
// call this function again? How can we achieve this?????
}
}
}
});
Kindly let me know how I can call that ajax call again that was supposed to run in the first place?
EDIT: Basically I have two AJAX calls i.e. one for authentication that gets the session ID and the other would be to get some data back based on that session ID. If the session ID expires mid way, I would like to redo the authentication call and then carry on with the AJAX call that was going to happen in the first place. Any suggestions on how I can achieve that?
I have added a diagram of it as well just to show what I would like to achieve.
Cheers.
retryLogin
has to perform an AJAX call, it will be asynchronous. You need to pass a callback to it, and the callback will call this function again. – Adalai