Hi my jQuery callback function does not work.
Competitor = {
addCompetitorForSave: function($data) {
$.post('/competition/add', $data , function($json) {
}, 'json');
return $json; // I need to return json data .
}
}
after this I need to do next .
var data = $('someForm').serialize();
var $json = Competition.addCompetitorForSave(data);
Thanks a lot.
The
postcompletes asynchronously but thealertruns synchronously. Hence theqavalue hasn’t been set yet. Instead of return a value here you need to pass an additional callback intoaddCompetitorForSave.