I have functions that make an AJAX call to get some data from the database.
function db (content) {$ .post ('/ ajax / db.php', {operation: content, content: content}, function (data) {console.log (data) ; Return data;}); }
console.log (data);
gives me the data that I need.
However how can I pass data to do the DB function so that I can do something like this:
var returned data = db ('material');
Thanks!
AJAX operations are asynchronous, so backing it directly is not an option, unless you have it Do not make synchronous (which locks the browser). Instead, you should provide data on the next function in the callback, such as:
function db (content) {$ .post ('/ ajax / db.php', {operation: operation, content : Content}, function (data) {next function (data);}); }
Or take a callback so that you can pass the function that receives the data when it is ready: like this:
Function db (content, callback) {$ .post ('/ ajax / db.php', {operation: operation, content: content}, callback); }
Then call upon giving callback function, for example:
DB ('content', function (data) {// data of Do something with}};
Comments
Post a Comment