site.get_discount_price = function(discount_id) {
return jQuery.ajax({
url: '/test.php/' + discount_id + '.json',
dataType: 'json',
success: function (data) {
return data.summa_vozvrata;
}
});
}
var discr_price = site.get_discount_price(discount_id);
console.log(discr_price);
site.get_discount_price(discount_id).done(function(data) {
var discr_price = data.summa_vozvrata;
console.log(discr_price);
});
// EDIT
site.get_discount_price = function(discount_id) {
var result;
jQuery.ajax({
url: '/test.php/' + discount_id + '.json',
dataType: 'json',
async: false,
success: function (data) {
result = data.summa_vozvrata;
}
});
return result;
}
site.get_discount_price = function(discount_id, callback) {
jQuery.ajax({
url: '/test.php/' + discount_id + '.json',
dataType: 'json',
success: function (data) {
if (callback) callback(data.summa_vozvrata);
}
});
}
/* ... */
site.get_discount_price(discount_id, function(summa) {
/* и уже здесь мы работаем с переменной summa */
});
site.get_discount_price = function(discount_id) {
jQuery.ajax({
url: '/test.php/' + discount_id + '.json',
dataType: 'json',
success: function (data) {
console.log(data.summa_vozvrata);
}
});
}