4 Types of Ajax asynchronous submission methods used in ExtJS

Source: Internet
Author: User
Tags html form json trim

  This article mainly introduces 4 kinds of Ajax asynchronous submitting methods commonly used in ExtJS, which can be referred to by friends in the following

/**    Code is as follows: * The first type of AJAX submission   * This approach requires direct use of the Ext Ajax method for submission   * Using this method, you need to encapsulate the parameters to be passed   * @return   * /  function saveuser_ajaxsubmit1 () {  Ext.Ajax.request ({  url: ' user_save.action ',  method: ' Post ' ,  params: {  userName:document.getElementById (' userName ') .value,  password:document.getElementById (' password ') .value },  success:function (response, Options) {  var o = Ext.util.JSON.decode ( Response.responsetext);  alert (o.msg); },  failure:function () { } }); }  nbsp * The second type of AJAX submission   * This way you will specify an HTML form for ext Ajax   * Using this method, you do not need to encapsulate the parameters to be passed   *  * @return   */  function Saveuser_ajaxsubmit2 () {  Ext.Ajax.request ({  url: ' user_save.action ',  method: ' Post ',  Form: ' UserForm ',//Specify form   success:function (response, Options) {  var o = Ext.util.JSON.decode (response.respo Nsetext);  alert (o.msg); },  FAilure:function () { } }); } /**  * The third type of AJAX submission   * This way will be submitted for Ext's own form   * Use this way, you need To use ext own TextField component   *  * @return   */  function saveuser_ajaxsubmit3 () { //define form   var for Mpanel = new Ext.formpanel ({  labelwidth:75,  frame:true,  bodystyle: ' padding:5px 5px 0 ',  Widt h:350,  defaults: {  width:230 },  defaulttype: ' TextField ',  items: [{  Fieldlabel : ' username ',  name: ' UserName ',  allowblank:false }, {  Fieldlabel: ' Password ',  name: ' Password ' &N Bsp }] }); //Definition window   var win = new Ext.window ({  title: ' Add user ',  layout: ' Fit ',  width:50 0,  height:300,  closeaction: ' Close ',  closable:false,  plain:true,  Bsp Buttons: [{  text: ' OK ',  handler:function () {  var form = Formpanel.getform ();  var userName = f Orm.findfield ('UserName '). GetValue (). Trim ();  var password = form.findfield (' password '). GetValue (). Trim ();  if (!username {  alert (' User name cannot be empty ');  return; }  if (!password) {  alert (' Password cannot be empty ');  return;  nbsp Form.submit ({  waittitle: ' Please later ... ',  waitmsg: ' Saving user information, please later ... ',  URL: ' user_save.action ',  metho D: ' Post ',  success:function (form, action) {  alert (action.result.msg); },  (for M, action) {  alert (action.result.msg); } }); } }, {  text: ' Cancel ',  handler:funct Ion () {  win.close (); } }] });  win.show (); } /**  * Fourth method of Ajax submission   * Such side form to convert HTML forms to Ext forms for asynchronous submissions   * Using this method, you need to define a good HTML form   *  * @return   */  function Saveuser_ AJAXSUBMIT4 () {  new Ext.form.BasicForm (' UserForm '). Submit ({  Waittitle: ' Please later ... ',  waitmsg: ' Saving user information , please later ... ',  URL: ' user_save.action ', &NBsp Method: ' Post ',  success:function (form, action) {  alert (action.result.msg); },  N (form, action) {  alert (action.result.msg); } }); }   
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.