如何从外部odoo向odoo控制器发出发布请求?

时间:2019-10-24 08:22:21

标签: python jquery ajax odoo

我正试图获得驱逐odoo的表格,所以我用网站构建器html_form_builder构建了该表格 我通过模块生成了html代码 使用action属性生成的表单

<form id="odoo_form" method="POST" action="http://localhost:8069/form/insert" enctype="multipart/form-data">
....
</form>

我用jquery代码扩展了HTML

$.ajax(my_form.attr('action'), {
            data: postData,
            processData: false,
            contentType: false,
            headers: {"Accept": "application/json" ,
            }, 
            success: function(data) {
                                    //alert('response data = ' + data);
                                    console.log('Success'); 
                                },
                                error: function (data) {
                                },
    type: 'POST'});

当您调用jquery代码时 控制器将被调用

@http.route('/form/insert', type="http", auth="public", csrf=False)
    def my_insert(self, **kwargs):
        return self.process_form(kwargs)

process_form将符合预期

if form_error:
    return json.JSONEncoder().encode({'status': 'error', 'errors': return_errors})

我已经看到了调用该函数的日志并返回/ 但我在jquery中收到此错误

POST https://localhost:8069/form/insert net::ERR_FAILED

1 个答案:

答案 0 :(得分:0)

我已经通过编辑控制器功能解决了问题

    @http.route('/form/insert', type="http", auth="public", csrf=False)
    def my_insert(self, **kwargs):
        body = self.process_form(kwargs)
        return request.make_response(body,{
            'Access-Control-Allow-Origin':  '*',
            'Content-Type': 'application/json',
            'Access-Control-Allow-Methods': 'GET',
            })


相关问题