1

I am trying to save nested data which is captured in a Form. (I also read this question)

Here is how the model looks like

Ext.define('App.model.Team',{
extend:'Ext.data.Model',
idProperty:'id',
fields:[
    {name:'id', type:'int'},
    {name:'name', type:'string'}, 
    {name:'description', type:'string'},
    {name:'orgUnitName', type:'string', mapping:'orgUnit.name'},  <----
],
proxy: {
    type:'ajax',
    url:'/odb/myteams/',
    reader: {
        type:'json',
        root:'data'
    }
}
});

In Controller...

  saveNewTeam: function( button, e, eOpts ) {

   win = button.up( 'window' ),
   form = win.down( 'form' ),
   isForm = form.getForm();  

    record = isForm.getRecord(),
    values = isForm.getValues(),
    record.set( values );

    var jsonData = Ext.JSON.encode(isForm.getValues());


    Ext.Ajax.request({
        url : '/odb/myteams',
        method : 'POST',
        headers : {
        'Content-Type' : 'application/json'
        },
        params : jsonData,
        success: function (form, action) {

            Ext.Msg.alert('Status', 'Saved successfully.');
            win.close();
        },
        failure: function (form, action) {
            if (action.failureType === Ext.form.action.Action.SERVER_INVALID) {
                Ext.Msg.alert('SERVER_INVALID', action.result.message);
            }
        } 
        });
   }, 

I get bad request exception.

POST http://odb/myteams?_dc=1407243897827 400 (Bad Request) 

looks like the data which is sent is not in correct json format?

This is what the server expects:

{
     name: "Operation addedd",
     description: "Operation DataBase",
     orgUnit:{
        name:'DATA DATAPROCESSING GMBH'
     }
}

This is how request is sent

{ 
     name: "Operation addedd",
     description: "Operation DataBase",
     orgUnitName:'DATA DATAPROCESSING GMBH'

}
Community
  • 1
  • 1
Sanjeev
  • 375
  • 1
  • 3
  • 14
  • ExtJs is sending correctly encoded json. Look at the data being sent and compare it to the format your backend requires. – Lorenz Meyer Aug 05 '14 at 19:23

0 Answers0