如何解决如何在ODOO中调用JSON RPC?
odoo.define('second_opinion.appointment',function(require) {
"use strict";
var ajax = require('web.ajax');
var core = require('web.core');
$(document).ready(function() {
$('#view_appointment').click(function(event){
ajax.jsonRpc("/my-appnt",'call',{
});
})
})
})
@http.route(['/my-appnts'],type="json",auth="user",csrf=False,methods=['POST'],website=True)
def appointment_form(self,**post):
apopointment = request.env['consultation'].search([])
values=({
'appointment':apopointment,})
return request.render("second_opinion.tmp_customer_form")
解决方法
您应该看到以下错误消息:
AttributeError:'JsonRequest'对象没有属性'render'
JSON-RPC 2
的请求处理程序方法的结果以JSON-RPC object的形式返回并包装在JSON-RPC Response中。
使用render
时HttpRequest
属性可用。
您使用jsonRpc
进行了正确的呼叫。问题出在请求处理程序中。
您可以在website_gengo中找到类似的示例,cotroller方法声明如下:
@http.route('/website/post_gengo_jobs',type='json',auth='user',website=True)
def post_gengo_jobs(self):
request.env['base.gengo.translations']._sync_request(limit=GENGO_DEFAULT_LIMIT)
return True
然后使用以下代码调用:
ajax.jsonRpc('/website/post_gengo_jobs','call',{});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。