I tried with no luck. When i remove it  it brings an error.

El domingo, 25 de octubre de 2020 a la(s) 19:19:29 UTC-3, trebor escribió:

> Walter,
>
>  
>
> If your copy and paste is accurate you have too many closing brackets in 
> the ajax section.
>
>  
>
> Try removing one of these from the end of the ajax section:
>
>     });
>
>  
>
>  
>
> *From:* django...@googlegroups.com <django...@googlegroups.com> *On 
> Behalf Of *Walter Randazzo
> *Sent:* Monday, 26 October 2020 9:09 AM
> *To:* django...@googlegroups.com
> *Subject:* Re: Error at the return of an AJAX POST in DJANGO
>
>  
>
> [External email] Please be cautious when clicking on any links or 
> attachments.
> ---
>
> hi there, 
>
> As far as I check its OK.
>
>  
>
> Thanks for replay.
>
>  
>
>  
>
>  
>
> El dom., 25 oct. 2020 a las 18:43, rbar...@xcaretresearch.com (<
> rbar...@xcaretresearch.com>) escribió:
>
> Not sure, but looks like an extra closing bracket in line 9 of the ajax 
> code
>
> On Sunday, October 25, 2020 at 2:05:28 PM UTC-7 wwran...@gmail.com wrote:
>
> Hi buddies, I have a POST request from ajax. At the backend some records 
> are updated in the django view, this is done fine but an error comes up and 
> the page isnt reloaded.
>
>  
>
> ***This is the error:***
>
>  
>
> > SyntaxError: Unexpected token O in JSON at position 0
>
>  
>
> ***This is the ajax:***
>
>  
>
>     $.ajax({
>
>     headers: { "X-CSRFToken": token },
>
>     "url": '/articulos/massup/', "type": "POST",
>
>     "dataType": "json", data: data,
>
>     success: function(e){
>
>     if(e="OK"){
>
>     location.reload(true);
>
>     }
>
>     },
>
>     error: function(a,b,c){
>
>     alert(c);
>
>     }
>
>     });
>
>     });
>
>  
>
> ***Thi is the view:***
>
>  
>
>     @csrf_exempt
>
>     def massup(request):
>
>         template_name = "articulos/articulos_ok.html"  
>
>         contexto={}  
>
>         if request.method=="GET":  
>
>             cat = Articulos.objects.all().order_by("codigo")  
>
>             contexto={"obj":cat}  
>
>         if request.method=="POST":  
>
>             codigos=request.POST.getlist("codigos[]")
>
>             porcentaje = codigos[0]#el primer elemento de la lista es el 
> porcentaje
>
>             porcentaje=Decimal(porcentaje)
>
>             codigos= [int(x) for x in codigos]#Convierte la lista en 
> integer
>
>             art_change = Articulos.objects.filter(pk__in=codigos)
>
>             i=0
>
>             for item in art_change:
>
>                 if i!=0: #Excluye el primer item ( el porcentaje)
>
>                     precioant=item.precio
>
>                     precionuevo=(precioant + (porcentaje * precioant/100))
>
>                     item.precio=precionuevo
>
>                     item.save()
>
>                 i=i+1
>
>             return HttpResponse("OK")
>
>         return render(request
>
> -- 
> 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...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/91f49db5-e89b-4df2-ab25-9ff61abec4bfn%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/91f49db5-e89b-4df2-ab25-9ff61abec4bfn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> -- 
> 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...@googlegroups.com.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAL7Dry6VivmQKU9sVwu%3Dhw9QXT35HUT7ySTZkAme3_AVu8Rb4w%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-users/CAL7Dry6VivmQKU9sVwu%3Dhw9QXT35HUT7ySTZkAme3_AVu8Rb4w%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a04b3af0-b3a1-4e90-800f-951409ef37d9n%40googlegroups.com.

Reply via email to