简体   繁体   English

如何将extjs数据从表单发布到服务器?

[英]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. 现在我面临着POST任务。 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? Ext.Ajax的参数定义了将通过url发布到服务器的数据? I can use this class for POST task or isn't the best way? 我可以将此类用于POST任务,还是不是最好的方法?

if you want to post form data you can use form.submit method instead of Ext.ajax .. 如果要发布表单数据,可以使用form.submit方法代替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 . 看看Ext.Ajax.request的ExtJs文档中的jsonData选项。

jsonData : Object/String jsonData:对象/字符串

JSON data to use as the post. 用作发布的JSON数据。 Note: This will be used instead of params for the post data. 注意:这将用于代替post数据的参数。
Any params will be appended to the URL. 任何参数都将附加到URL。

So your Ajax request should look like 所以您的Ajax请求应该看起来像

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 . 当您想提交GET和POST数据时,可以使用paramsjsonData

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 }) } } 
Thanks for answers! 感谢您的回答!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM