populate value of a field from another table
populate value of a field from another table
amir7sh
Posts: 15Questions: 4Answers: 0
in DataTables
Hello friends
I want populate value of a field from another table use jquery $.ajax method
code :
{ data: null,
render : function ( data, type, full, meta ) {
$.ajax({
type: "POST",
url: "funcs.php",
data: {id : data.id},
dataType: "json",
processdata: true,
cache: false,
success: function (json) {
result = json;
}
});
return result;
}
}
But the code did not work and I saw this error :
ReferenceError: result is not defined .
Where is the problem?
This discussion has been closed.
Replies
"result" is only defined in your "success" function. No success - no result - result is undefined where you try to return it.
You need to recall what the first letter of Ajax means - Asynchronous. You could use
async
in the jQuery options list to disable that, but I would suggest that is an extremely bad idea - it will kill performance and you'll DDoS your own server.I would suggest rethinking what you are actually trying to do.
Allan
Thank Allan , What's the right way to do it?
I want to have the total price from the other table .
OK tangerine , What is the correct method?
I would suggest that you should modify the data that is returned from the server (assuming you are ajax loading the data - there is no way of knowing without a test case) to include all of the information required. It will be far faster doing that that it will be making 4 * num_rows calls to the server - where
num_rows
is the number of rows of course (because that is what your code above would be doing).Allan