Как вернуть значение переменной name во втором $.get?
Вызываю ф-ю таким образом:
var all = Price(url);
При этом all - пустая.
function Price(url) {
var res = null;
$.get(url, function(data){
var pattern = /"market_hash_name":"(.*?)"/;
var match = data.match(pattern);
var name = match[1];
$('#wrapper').html('name = ' + encodeURIComponent(name));
if (name) {
var url2 = 'http://steamcommunity.com/market/priceoverview/?currency=5&appid=730&market_hash_name=' + encodeURIComponent(name);
$.get(url2, function(data){
var pattern = /"lowest_price":"(.*?)"/;
var match = data.match(pattern);
var name = match[1].split('p')[0];
$('#w').html(name);
res = name;
}, "html");
}
}, "html");
return res;
}
Код, где вызывается ф-я:
for (var i = 0; i < whil.size(); i++) {
$('.primary:last', data).children('.tradeoffer_item_list').children('.trade_item').each(function(i) {
one.push($(this).attr("data-economy-item").split('/')[2]);
two.push($(this).attr("data-economy-item").split('/')[3]);
});
Price("http://steamcommunity.com/economy/itemhover/730/2/" + one[i] + "?o=" + two[i], function(res) {
all += res;
});
}
$('#w').html(all);
Price("http://steamcommunity.com/economy/itemhover/730/2/" + one[i] + "?o=" + two[i], function(res) { all = res; });сделал так, но переменной all ничего не присвоилось. Мне нужно что бы результат ф-и записался в переменную. – Slavik Okara Jul 31 '15 at 07:56