Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
11245 Lượt xem

I try to get data from odoo server using js, but I have a problem when I print this data I get undefined how I can solve this problem I want to get this data outside .then

        var ajax = require('web.ajax');
        var result;
        ajax.jsonRpc("/get_data", 'call', {}, {
            'async': false
        }).then(function (data) {
            result = data;
        });
        console.log(result); // undefined

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

Can you try the code like below

var ajax = require('web.ajax');
var result = [];
ajax.jsonRpc("/get_data", 'call', {}, {
'async': false
}).then(function (data) {
result.push(data);
});
console.log(result)

Regards

Ảnh đại diện
Huỷ bỏ

For me it's works!

i have added return result ; statement at last it is returning empty array..how can return that value?

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 20
6513
0
thg 7 25
295
1
thg 7 25
5074
0
thg 7 25
640
0
thg 6 25
710