I'm trying to build a jQuery ajax function which is totally generic. It would receive all the data and even request type as parameters. After that it will substitute in the respective variables and build the request. Here is the code...
function server_request (type, url, dataType, data) {
var packet;
var response = null;
if (packet) {
packet.abort();
};
if (type == "get") {
packet = $.ajax({ type: type, url: url, dataType: dataType });
packet.done(function(returned_data){
response = returned_data;
});
}
return response;
response = null;
}
So I want the received data to be stored in an already declared variable called "response" and I want it to be returned for use in another place. Somehow its not working and it keeps returning the predefined value of the response variable. can someone help??
Aucun commentaire:
Enregistrer un commentaire