1

I am trying to submit a form to the server with the params in JSON.

form.submit({
  url:'JSONSaveEntry',
  method:'POST'
});

but it sends everything as form-www-urlencoded.

I already checked that no field has isFile set to true (but then, it would send as multipart-formdata) and that standardSubmit is false.

I also tried to use

Ext.Ajax.request({
  url:'JSONSaveEntry',
  method:'POST',
  params:form.getValues()
});

and

Ext.Ajax.request({
  url:'JSONSaveEntry',
  method:'POST',
  params:Ext.encode(form.getValues())
});

Every submission is done as form-www-urlencoded, although the docs clearly state "Performs a Ajax-based submission of form values (if standardSubmit is false)". But then, this sentence is already proven wrong because whenever a file field is in the form, the form is submitted as multipart.

So, does anyone know how I can get the form submitted as JSON?

Possibility 2: I know that it works if I submit a model via model.save(), but how would I create a model from a form on-the-fly (without hardcoding the fields twice)?

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • What about if you gave a param object such as `params:{myJson:Ext.encode(form.getValues())}` and then on the serverside JSON_decode the parameter which should give you your JSON object? – Rob Schmuecker Jan 16 '15 at 09:25

1 Answers1

2

I think below would solve your purpose.

Ext.Ajax.request({
  url:'JSONSaveEntry',
  method:'POST',
  headers: { 'Content-Type': 'application/json' },
  jsonData : JSON.stringify(form.getValues()),
  success : function(response){ console.log("response from server")},
  failure : function(error){console.log(error)}
});
dReAmEr
  • 6,986
  • 7
  • 36
  • 63