تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
11222 أدوات العرض

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?

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 20
6492
0
يوليو 25
269
1
يوليو 25
5041
0
يوليو 25
605
0
يونيو 25
689