I am trying to call a controller function from js and use the result for validation purpose.
Unfortunately, the result getting as `undefined` because of the result line is printing before the completion of the ajax call.
here is my code:
***.js**
send: function(e){
e.preventDefault();
var self = this;
var is_submit = self.$target.find('#is_submit').val();
var mobile = self.$target.find('#mobile').val();
var phone = self.$target.find('#phone').val();
var data = self.ajaxcall(mobile,e);
console.log('dddddddd',data);// here it prints undefined.
if (data == false){
return false;
}
this._super(e);
},
})
ajaxcall:function(mobile,e){
var value = {
'flag':'mobile',
'number':mobile
}
ajax.jsonRpc('/checkexisting/','call',value).then(function(data){
console.log('isnide ajax call',data);
return data;
});
},
Here is th console output:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/SK4ib.png
How can i make it as a synchronous mode?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
4165
Lượt xem
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
0
thg 7 17
|
2849 | ||
|
0
thg 3 15
|
6419 | ||
|
1
thg 8 25
|
2123 | ||
|
0
thg 11 23
|
1841 | ||
|
1
thg 5 20
|
11903 |
Have you tried $.when() ?
Grep for examples in the mail module js folder...
@Pablo Guerra, I searched this in the source code and found it. But i didn't understand. Could you give a concrete solution?
I'm not sure if it works. something like
var xyz
xyz= ajax.jsonRpc('/checkexisting/','call',value) //I'm assuming that this returns some value from server.
$.when(xyz).pipe(function(result){return result}))