0

I have a piece of code which goes as following:

 var o_titular = {id:'01',fecha:'2014-01-01'};
 var o_dependientes = [
     {id:'02',fecha:'2014-02-02'},
     {id:'03',fecha:'2014-03-03'}
 ];
 var o_fecha = '2014-05-05';
 $("#documento-antiguedad").ajaxSubmit({
     dataType: 'json',
     data: {
         titular: o_titular,
         dependientes: o_dependientes, 
         fecha: o_fecha
     },
     success: function(r) {
         alert("yay success");
     }
 });

I'm forced to make this ajaxSubmit (this is a simplified code, but the complete case involves file uploading and such) but when I see the data I send in the POST request i got the following:

titular [object Object]
dependientes    [object Object],[object Object]
fecha   2014-05-05

of course I want to fiddle with the content of the objects, not the object itself. How can I send this parameters as JSON objects with ajaxSubmit?

Thank you in advance

EDIT:

When I make a regular ajax call:

var o_titular = {id:'01',fecha:'2014-01-01'};
var o_dependientes = [
{id:'02',fecha:'2014-02-02'},
{id:'03',fecha:'2014-03-03'}
];
var o_fecha = '2014-05-05';
$.ajax({
    url:'/pendientes/index/creatependienteantiguedad/',
    dataType: 'json',
    data: {
        titular: o_titular,
        dependientes: o_dependientes, 
        fecha: o_fecha
    },
    success: function(r) {
        alert("yay success");
    }
});

I get the following:

dependientes[0][fecha]  2014-02-02
dependientes[0][id] 02
dependientes[1][fecha]  2014-03-03
dependientes[1][id] 03
fecha   2014-05-05
titular[fecha]  2014-01-01
titular[id] 01

That's exactly what I want to get, but with ajaxSubmit instead of Ajax.

jdlcgarcia
  • 183
  • 11

1 Answers1

0

You could use:

JSON.stringify(o_dependientes);

That will turn the JSON object into a string

Jeroen Flamman
  • 965
  • 6
  • 10
  • I receive just '{' or '[' – jdlcgarcia Feb 11 '15 at 19:30
  • Did you do the same with o_titular? That's also a JSON object that needs to be stringyfied.. `titular: JSON.stringify(o_titular), dependientes: JSON.stringify(o_dependientes), fecha: o_fecha ` – Jeroen Flamman Feb 11 '15 at 22:56
  • With o_fecha I don't have a problem, as long as is simple data. Objects all return wrong data because of double quotes. I won't use ajaxSubmit to share objects. – jdlcgarcia Feb 12 '15 at 14:57