Four Ajax asynchronous submissions commonly used in extJs

Source: Internet
Author: User
/**
* The first Ajax submission method
* In this method, you must directly use the ext Ajax Method for submission.
* To use 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 (){
}
});
}
/**
* Second Ajax submission method
* This method specifies 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', // specifies the form
Success: function (response, options ){
Var o = Ext. util. JSON. decode (response. responseText );
Alert (o. msg );
},
Failure: function (){
}
});
}
/**
* Third Ajax submission method
* This method is used to submit the ext form.
* To use this method, you must use ext's textField component.
*
* @ Return
*/
Function saveuser_ajaxsubmit3 (){
// Define the 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'
}]
});
// Define the 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 blank ');
Return;
}
If (! Password ){
Alert ('password cannot be blank ');
Return;
}
Form. submit ({
WaitTitle: 'Please wait ...',
WaitMsg: 'saving user information. Please wait ...',
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 ();
}
/**
* Method 4: Ajax submission
* In this way, html forms are converted to ext forms for asynchronous submission.
* To use this method, you must define the html form.
*
* @ Return
*/
Function saveUser_ajaxSubmit4 (){
New Ext. form. BasicForm ('userform'). submit ({
WaitTitle: 'Please wait ...',
WaitMsg: 'saving user information. Please wait ...',
Url: 'user _ save. action ',
Method: 'post ',
Success: function (form, action ){
Alert (action. result. msg );
},
Failure: function (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.