我有这个错误 - jquery.min.js: 2 Uncaught TypeError: Illegal invocation django

时间:2021-01-18 04:28:18

标签: django ajax

我正在尝试保存订单详细信息数据,但出现此错误。

jquery.min.js: 2 Uncaught TypeError: Illegal invocation

我仍在将该数据发送到数据库的过程中,我只是想看看它是否可以通过这行代码正常工作:

vents = request.POST['ventas']

JS

    $('form').on('submit', function (e) {
        e.preventDefault();
        var parametros = new FormData();
        parametros.append('action', $('input[name="action"]').val());
        parametros.append('ventas', JSON.stringify(ventas.items));
        submit(window.location.pathname, parametros, function(){
            location.href = "{% url 'Venta' %}";

        });
    });

视图

def post(self, request, *args, **kwargs):
        data = {}
        try:
            action = request.POST['action']
            if action == 'autocomplete':
                productos = Producto.objects.filter(nombre__icontains=request.POST['term'])[0:10]
                for i in productos:
                    data = []
                    item = i.toJSON()
                    item['value'] = i.nombre
                    data.append(item)
            elif action == 'add':
                vents = request.POST['ventas']
            else:
                data['error'] = 'No ha ingresado a ninguna opción'
        except Exception as e:
            data['error'] = str(e) 
        return JsonResponse(data,safe=False)

1 个答案:

答案 0 :(得分:0)

在你的 js 中:

       $('form').on('submit', function (e) {
        e.preventDefault();
        var parametros = new FormData();
        parametros.append('action', $('input[name="action"]').val());
        parametros.append('ventas', JSON.stringify(ventas.items));
        submit(window.location.pathname, parametros, function(){
            location.href = "{% url 'Venta' %}";

        });
    })

去掉尾随的';'在最后一个 ')' 结束时。当我遇到这个问题时对我有用!