Re: Error at the return of an AJAX POST in DJANGO

2020-10-26 Thread Nikitha Bangalore Escorts
hmm


On Monday, October 26, 2020 at 2:35:28 AM UTC+5:30 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5111b355-45c4-4525-8af9-b726869c46fdn%40googlegroups.com.


Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread Walter Randazzo
HI Mac,
I've changed the if statement  to if(e=="OK")  but  the message error 
persist.
Note: I have explore the value of the return in the webbrowser dev tools 
and it contains "OK"


El domingo, 25 de octubre de 2020 a la(s) 21:06:00 UTC-3, Mac escribió:

> In your success function, you are assigning the variable e = 'OK', so in 
> your if statement, it appears to throw an error. If you change it to  
> if(e=="OK"), does it work? Note the two equal signs, == .
>
> On Sun, Oct 25, 2020 at 3:29 PM Walter Randazzo  
> wrote:
>
>> 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  *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
>>>  
>>> 
>>> .
>>>
>>> -- 
>>> 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
>>>  
>>> 
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails 

Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread leon.vaks

Sent from my Samsung Galaxy smartphone.
 Original message From: Walter Randazzo  
Date: 10/25/20  6:10 PM  (GMT-05:00) To: django-users@googlegroups.com Subject: 
Re: Error at the return of an AJAX POST in DJANGO hi there, As far as I check 
its OK.Thanks for replay.El dom., 25 oct. 2020 a las 18:43, 
rbar...@xcaretresearch.com () escribió:Not sure, 
but looks like an extra closing bracket in line 9 of the ajax codeOn 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+unsubscr...@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.




-- 
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/CAL7Dry6VivmQKU9sVwu%3Dhw9QXT35HUT7ySTZkAme3_AVu8Rb4w%40mail.gmail.com.

-- 
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/5f9618f9.1c69fb81.6f201.01e1%40mx.google.com.


Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread leon.vaks

  t.f  Sent from my Samsung Galaxy smartphone.
 Original message From: Walter Randazzo  
Date: 10/25/20  6:10 PM  (GMT-05:00) To: django-users@googlegroups.com Subject: 
Re: Error at the return of an AJAX POST in DJANGO hi there, As far as I check 
its OK.Thanks for replay.El dom., 25 oct. 2020 a las 18:43, 
rbar...@xcaretresearch.com () escribió:Not sure, 
but looks like an extra closing bracket in line 9 of the ajax codeOn 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+unsubscr...@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.




-- 
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/CAL7Dry6VivmQKU9sVwu%3Dhw9QXT35HUT7ySTZkAme3_AVu8Rb4w%40mail.gmail.com.

-- 
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/5f9618f8.1c69fb81.6f201.01de%40mx.google.com.


Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread Malcolm MacKinnon
In your success function, you are assigning the variable e = 'OK', so in
your if statement, it appears to throw an error. If you change it to
if(e=="OK"), does it work? Note the two equal signs, == .

On Sun, Oct 25, 2020 at 3:29 PM Walter Randazzo 
wrote:

> 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  *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
>> 
>> .
>>
>> --
>> 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
>> 
>> .
>>
> --
> 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
> 
> .
>

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

Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread Walter Randazzo
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  *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
>  
> 
> .
>
> -- 
> 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
>  
> 
> .
>

-- 
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.


RE: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread 'Trevor Woolley' via Django users
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-users@googlegroups.com  On Behalf 
Of Walter Randazzo
Sent: Monday, 26 October 2020 9:09 AM
To: django-users@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.

[https://docs.google.com/uc?export=download=0B2naFBGBGbW3cUwtdVJYYUo4bkU=0B2naFBGBGbW3aG9wM3E3TDJ0aE9wMWlOZkcwNnBlRURFZkZJPQ]


El dom., 25 oct. 2020 a las 18:43, 
rbar...@xcaretresearch.com 
(mailto:rbarh...@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+unsubscr...@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.
--
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/CAL7Dry6VivmQKU9sVwu%3Dhw9QXT35HUT7ySTZkAme3_AVu8Rb4w%40mail.gmail.com.

-- 
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/SYAPR01MB29126761B62375E2671892A4AF180%40SYAPR01MB2912.ausprd01.prod.outlook.com.


Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread Walter Randazzo
hi there,

As far as I check its OK.

Thanks for replay.



El dom., 25 oct. 2020 a las 18:43, rbar...@xcaretresearch.com (<
rbarh...@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+unsubscr...@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
> 
> .
>

-- 
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/CAL7Dry6VivmQKU9sVwu%3Dhw9QXT35HUT7ySTZkAme3_AVu8Rb4w%40mail.gmail.com.


Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread Walter Randazzo
HI Macolm,

I am checking out  the response value in the  and it shows OK in the
browser dev tool . So i guess the function is not defined properly

[image: image.png]

El dom., 25 oct. 2020 a las 18:46, Malcolm MacKinnon ()
escribió:

> I'm not a JS expert, but is your success function defined properly?
> if(e="OK") vs. if(e=="OK")
>
> On Sun, Oct 25, 2020 at 2:06 PM Walter Randazzo 
> 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+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/124085ff-0700-4361-9377-02596b161c4fn%40googlegroups.com
> .
>
> --
> 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/CAK8W3Xrftk-3SeGp-EmJVtPzhvWYQp-ZigkHouLOEpDd1W%2B8FA%40mail.gmail.com
> .
>

-- 
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/CAL7Dry6ofhrTb__NmTdKXK9Pi9ODtzWDX6GVMfRc916WjB9aXw%40mail.gmail.com.


Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread Malcolm MacKinnon
I'm not a JS expert, but is your success function defined properly?
if(e="OK") vs. if(e=="OK")

On Sun, Oct 25, 2020 at 2:06 PM Walter Randazzo  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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/124085ff-0700-4361-9377-02596b161c4fn%40googlegroups.com.

-- 
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/CAK8W3Xrftk-3SeGp-EmJVtPzhvWYQp-ZigkHouLOEpDd1W%2B8FA%40mail.gmail.com.


Re: Error at the return of an AJAX POST in DJANGO

2020-10-25 Thread rbar...@xcaretresearch.com
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+unsubscr...@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.