I am having design issues regarding conditions combined with ajax calls in javascript with the jquery library. Depending on a condition I want to make some ajax-call and then do a procedure - or i do the same procedure without ajax call.
edit 1; to be more concrete with what I wanna achieve:
Depending if some object data already exists I either load it from my local array of objects or otherwise with ajax.
I came up with this structure:
if(x)
{
$.ajax({
url: "interface.php",
type: "GET",
dataType: "json",
data:{
my_data : testvalue
}
})
.done(function(data){
/* PROCEDURE A */
});
}
else
{
// same procedure
/* PROCEDURE A */
}
I don't like that I have to repeat the exact same code here. I could of course pack the procedure into a function, but that would not change the design.
I would like to have a structure like this:
if(x)
{
$.ajax({
url: "interface.php",
type: "GET",
dataType: "json",
data:{
my_data : testvalue
}
});
}
/* PROCEDURE A*/
so if x == true
do the ajax call first. but do "PROCEDURE A" always.
but that's not possible of course because of the asynchronicity of it.
something else that came to my mind is a pseudo-ajax call, but I don't know how this would work out.
thanks for any help and suggestions!