I am trying to send an object in json:
{
'salario' : 0,
'usuario' : {
'nombre' : 'usuario1',
'bono' : null,
'uf' : null,
'ultimaRenta' : 1698567,
'utm' : null
},
'empleado' : 12,
'param' : {
'movilizacion' : 46786.0
},
'ahorro' : 84525
}
In an ajax:
$.ajax({
url : url2,
dataType : 'jsonp',
type : 'POST',
data : jsonEnviado,
jsonpCallback : "myJSON",
success : function(data, textStatus, jqXHR) {
var rentaFinal = data.renta;
var num = data.renta;
num = num.toString().split('').reverse().join('').replace(
/(?=\d*\.?)(\d{3})/g, '$1.');
num = num.split('').reverse().join('').replace(/^[\.]/, '');
rentaFinal = num;
document.getElementById('renta').innerHTML = "$" + rentaFinal;
}
});
But when fetching it from the controller, the object comesnull
the method signature is:public String calculaRenta(HttpServletRequest req){
And I am getting the object with:req.getParameter("jsonEnviado");
I have searched for a way to do an encode but it has not worked for me.
Try instead of sending:
Send:
This is so that the json becomes a request parameter and you can do the conversion on the server.