E
E
Evgeny Ivanov2018-02-05 11:39:32
JavaScript
Evgeny Ivanov, 2018-02-05 11:39:32

How to assign a value to a variable from a function?

I'm trying to pass the result of getJSON to the y variable - i.e. val.
How can I do it?
The code is working, alert(val) shows.

var y;
//y=$.getJSON('actions.php?................return val;});}); не работает и наверно не должно
$.getJSON('actions.php?get_live_data', function(live_data) {
$.each(live_data, function(key, val) {
//y=val; так не работает
//alert(val); //выводит число т.е. моя функция работает
//return val; вообще не работает, тк. скорее всего и не предусмотрено в getJSON
});});
//y=val; и так не работает

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question