Tyomik_mnemonic
Tyomik_mnemonic

Reputation: 946

How to post extjs data from form to server?

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?

Upvotes: 1

Views: 4913

Answers (3)

Tyomik_mnemonic
Tyomik_mnemonic

Reputation: 946

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
                	})
                }
}
Thanks for answers!

Upvotes: 0

Nishant Bajracharya
Nishant Bajracharya

Reputation: 361

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){

            }
      });
 }

Upvotes: 3

And-y
And-y

Reputation: 1524

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
    }
});

Upvotes: 1

Related Questions