4 kinds of asynchronous submitting methods used in ExtJS _extjs

Source: Internet
Author: User
Tags html form trim
/**
Copy Code code as follows:

* The first type of AJAX submission
* This approach needs to be submitted directly using the EXT Ajax method
* 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 () {
}
});
}
/**
* The second type of AJAX submission
* This way 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 forms
Success:function (response, options) {
var o = Ext.util.JSON.decode (response.responsetext);
alert (o.msg);
},
Failure:function () {
}
});
}
/**
* The third way of submitting Ajax
* This way will be submitted for Ext's own form
* Using this method, you need to use Ext's own TextField component
*
* @return
*/
function Saveuser_ajaxsubmit3 () {
Defining a Form
var formpanel = new Ext.formpanel ({
Labelwidth:75,
Frame:true,
Bodystyle: ' padding:5px 5px 0 ',
WIDTH:350,
Defaults: {
width:230
},
DefaultType: ' TextField ',
Items: [{
Fieldlabel: ' username ',
Name: ' UserName ',
Allowblank:false
}, {
Fieldlabel: ' Password ',
Name: ' Password '
} ]
});
Definition window
var win = new Ext.window ({
Title: ' Add User ',
Layout: ' Fit ',
WIDTH:500,
HEIGHT:300,
Closeaction: ' Close ',
Closable:false,
Plain:true,
Items:formpanel,
Buttons: [{
Text: ' OK ',
Handler:function () {
var form = Formpanel.getform ();
var userName = Form.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
}
Form.submit ({
Waittitle: ' Please later ... ',
Waitmsg: ' Saving user information, please later ... ',
URL: ' User_save.action ',
Method: ' Post ',
Success:function (form, action) {
alert (action.result.msg);
},
Failure:function (form, action) {
alert (action.result.msg);
}
});
}
}, {
Text: ' Cancel ',
Handler:function () {
Win.close ();
}
} ]
});
Win.show ();
}
/**
* The fourth kind of Ajax submission method
* This way translates HTML forms into Ext forms for asynchronous submission
* 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 ',
Method: ' Post ',
Success:function (form, action) {
alert (action.result.msg);
},
Failure:function (form, action) {
alert (action.result.msg);
}
});
}

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.