Help

0

How to call a function from JS file

Avatar
simes93124

i set a keyDown from JS file call a function in Py file

but i got this error :

  • /some/route: Function declared as capable of handling request of type 'http' but called with a request of type 'json'

Anyone can help me fix this


  • this is my JS file 

_onKeydown_searchText: function () {
    var self = this;
    var search = {};
    search.Input = self.$('#text_input').val().trim();
    if (event.keyCode == 13 && search.Input) {
        console.log("haha");
        return this._rpc({
        route: '/some/route',
        params: { search: search.Input }
        }).then(function (data) {
        console.log(data);
        self._result = data;
        })
    }
},

and this is my Py fucntion

@http.route('/some/route/'website=Trueauth='public'csrf=False)
    def get_data(self, **kw):
        print(kw)
        print("================haha")
        condition = kw['search']
        sql = """
            select name from res_partner where phone = '%s' or email = '%s'
        """ % (condition, condition)
        http.request.cr.execute(sql)
        result = http.request.cr.fetchall() or []
        data = []
        list(data)
        for x in result:
            temp = ''.join(x)
            data.append(temp)
        return http.request.render("search_vip_route.get_data", {
            'data': data
        })


アバター
破棄
1 回答
0

You will have to add type="json" to handle the JSON request from JS.

@http.route('/some/route/', website=True, auth='public', csrf=False, type="json")


アバター
破棄