no puedo asignar una tarea con jquery

1
0
-1

Hola gente, espero puedan ayudarme, tengo un problema al intentar hacer un "PUT" con jquery: tengo los siguiente errores:

-exception: "class org.json.simple.parser.ParseException" -"class java.lang.IllegalArgumentException" -message: "Can't parse JSon"

mi código es el siguiente:

-variables de ejemplo- var usuario_id="2" var id_tarea="5"

tomarTarea = function(id_tarea) {
$.ajax({url:"/bonita/API/bpm/humanTask/"+id_tarea, data: {"assigned_id":usuario_id}, type: 'PUT', success: function () { alert("la tarea a sido asignada a ud."); }}); };

¿Que estoy haciendo mal?

Comments

Submitted by florian.baillagou on Wed, 03/11/2015 - 14:51

Hi,

Can't you use angular to convert your data as JSON ? link here

You may have to specify the content-type of your request.

And what can you see into your data variable using Javascript debugger ?

Submitted by marcosjeda93 on Wed, 03/11/2015 - 15:27

what content type should I use? and.. I don't know how to use angular.. should I learn it? uh!.. I hope you can see this: http://prntscr.com/6fg4h0

http://prntscr.com/6fg4u6
Submitted by florian.baillagou on Wed, 03/11/2015 - 15:51

Yep, I can see these pictures. You set the content-type "application/json" to your request.

$.ajax({url:"/bonita/API/bpm/humanTask/"+id_tarea, data: dataJson , contentType:"application/json", type: 'PUT', success: function () { alert("la tarea a sido asignada a ud."); }});

I think your data are URL encoded since you dont specify a contentType and it modifies your {"assigned_id":usuario_id} to assigned_id=usuario_id

Submitted by marcosjeda93 on Wed, 03/11/2015 - 15:56

so... what can I do? o.O

Submitted by florian.baillagou on Wed, 03/11/2015 - 15:57

Set the contentType !

$.ajax({url:"/bonita/API/bpm/humanTask/"+id_tarea, data: dataJson , contentType:"application/json", type: 'PUT', success: function () { alert("la tarea a sido asignada a ud."); }});

Submitted by marcosjeda93 on Wed, 03/11/2015 - 16:00
1 answer

1
0
-1

Hi,

Found the solution while discussing on gmail.

The data needs to be a string. In this case : '{"assigned_id":"2"}' or the data is URLendoded (by the ajax call ? I don't know) and the ':' is replaced by '=' that cause a "Can't parse JSON" error.

You can use this function : Stringify

Notifications