Hello,

I was wondering how I can send a response JSON in a good way, because I 
have the next code:

if "product_id" in request.POST:
            try:
                id_producto = request.POST['product_id']
                p = Pozo.objects.get(pk=id_producto)
                mensaje = {"status":"True","product_id":p.id}
                p.delete() # Elinamos objeto de la base de datos
                return JsonResponse(mensaje)
            except:
                mensaje = {"status":"False"}
                return JsonResponse(mensaje)

And my JS function doesn't work with this code:

   var options = {
        success:function(response)
        {
            if(response.status=="True"){
                alert("Eliminado!");
                var idProd = response.product_id;
                var elementos= $(nombre_tabla+' >tbody >tr').length;
                if(elementos==1){
                    location.reload();
                }else{
                    $('#tr'+idProd).remove();
                    $(nombre_ventana_modal).modal('hide');
                }
            }else{
                alert("Hubo un error al eliminar!");
                $(nombre_ventana_modal).modal('hide');
            };
        }
    };
    $(nombre_formulario_modal).ajaxForm(options);
});

And I don't know what I can do. Does anyone have any idea?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2cfc6283-ee2f-4280-b086-2dc1595855c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to