Reputation: 2670
How can I post username/password as Raw JSON via form.submit().
loginForm.submit({
url: 'localhost/login',
method: 'post',
jsonData: loginForm.getValues()
...
success: ...
even with Ext.JSON.encode(loginForm.getValues())
server is receiving as username=test&password=test which I need to be {"username":"test","password":"test"}
Upvotes: 0
Views: 3157
Reputation: 1603
As is often the case with ExtJS, there's an easy answer. In the config of the loginForm:
Ext.create('Ext.form.Panel', {
title: 'Simple Form',
// The form will submit an AJAX request to this URL when submitted
url: 'save-form.php',
.... (blah blah blah)
jsonSubmit: true // <---- set this to TRUE
});
Set the property jsonSubmit: true
.
Then when you use loginForm.submit()
, your object will be submitted as JSON rather than form params.
Here's a link to the form docs: http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.form.Panel
Upvotes: 2
Reputation: 2670
When a form is submitted, it is not submitted in JSON format. In order to submit JSON string, Ext.Ajax.request must be used. http://www.sencha.com/forum/showthread.php?132082-jsonData-in-submit-action-of-form
I just had to change
loginForm.submit({})
to
Ext.Ajax.request({})
and use
params: Ext.JSON.encode(loginForm.getValues()),
Bad DOCS.
Upvotes: 0
Reputation: 19758
You should probably try something like
Ext.Ajax.request({
method: 'POST',
url: 'submit.php',
params : {
data: Ext.encode(loginForm.getValues())
},
success: function() {
},
failure: function() {
}
});
Upvotes: 3