Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
11365 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง

For me it's works!

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ค. 20
6601
0
ก.ค. 25
426
1
ก.ค. 25
5324
0
ก.ค. 25
864
0
มิ.ย. 25
868