I have understood how to GET data from server to application. Now I face with POST task. I have form, and want post fields data to server by clicking on button.
I trying to use this:
{//some controllercode
xtype: 'button'
text: 'save',
ui: 'confirm',
scope: this,
handler: function() {
Ext.Ajax.request({
url:'/api/renter/',
method: 'POST',
params: {
ReplaceAllRefs: true
}
})
}
}
what the parameter of Ext.Ajax defines data which will post to server through url? I can use this class for POST task or isn't the best way?
if you want to post form data you can use form.submit
method instead of Ext.ajax
..
var form = your_form_panel.getForm();
if(form.isValid()){ //isValid() will validate all your form fields
form.submit({
url : '/api/renter/',
params: params, //additional parameters can be send in object
success: function(form, o){
},
failure: function(form, o){
}
});
}
Have a look at the ExtJs documentation of Ext.Ajax.request for the option jsonData
.
jsonData : Object/String
JSON data to use as the post. Note: This will be used instead of params for the post data.
Any params will be appended to the URL.
So your Ajax request should look like
Ext.Ajax.request({
url:'/api/renter/',
method: 'POST',
jsonData: {
ReplaceAllRefs: true
}
});
When you want to submit GET and POST data you can do it with params
and jsonData
.
Ext.Ajax.request({
url:'/api/renter/',
method: 'POST',
params: {
someGetParam: 'value'
},
jsonData: {
ReplaceAllRefs: true
}
});
In the end i have used this block of code:
{ text: 'save', ui: 'confirm', handler: function() { var dataup3 = this.up().items.items[0]; //get form's fields level var dataSet3 = dataup.getValues(); Ext.Ajax.request({ url:'/api/cutarea/', method: 'POST', params: dataSet3 }) } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.