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?
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
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 ?
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
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
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.”);
}});