This question has already been answered:
Hello. I can not understand what the snag is. I am writing a simple function, as in the example below:
function setCookie(val) { var arr = new Object(); $.ajax({ type: 'post', dataType: 'json', url: 'index.php', data: { val: val, query: 'set-cookie' }, success: function(data) { // тут возвращается, как и должно, число и без массивов: 100 console.log(data); // заношу в объект число, которое пришло с запроса arr = { 'data': data }; } }); // в итоге мне возвращается: Object {} undefined console.log(arr, arr['data']); return arr; }
The value is lost when inserted into the object. How to bring in the object that came from the request? It seems at the top created the desired global variable, and no result.