How can I get a FormPanel to POST JSON with ExtJS 3.1.0?
문제
By default, a FormPanel
in ExtJS 3.1.0 posts the form fields as application/x-www-form-urlencoded
when you call its submit() function.
Is there any way to get it to post JSON instead?
해결책
You can use getValues()
to pull the values and then Ext.encode()
them and manually do an Ext.Ajax.request({})
with this data as well.
다른 팁
You probably want to extend Ext.form.Action.Submit
to encode the params as JSON instead of url-encoding them in the body.
You can override Ext.form.Action.Submit.run
.
Just like this:
Ext.override(Ext.form.Action.Submit, {
run: function() {
// Your code here
}
});
Just put in params
var formData = App.formPanel.getValues(false);
Ext.net.DirectMethod.request({
url: '/Product/Save',
params: formData,
success: function(jsonResult){
}
});
or
App.formPanel.submit();
Before set a App.formPanel.url = '/Product/Save'
제휴하지 않습니다 StackOverflow