Skip to Content
Menu
This question has been flagged
1 Reply
6396 Views

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
        })


Avatar
Discard
Best Answer

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")


Avatar
Discard
Related Posts Replies Views Activity
1
Jun 22
4011
1
Nov 21
1875
2
May 24
1052
0
Feb 23
1273
0
May 21
3816