There are four Ajax asynchronous commit methods commonly used in extJS

  • 2020-03-30 02:18:45
  • OfStack

/**
 
*  The first kind of Ajax submission  
*  This method needs to be used directly ext Ajax Method to commit  
*  In this way, 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() { 
} 
}); 
} 
 
function saveUser_ajaxSubmit2() { 
Ext.Ajax.request( { 
url : 'user_save.action', 
method : 'post', 
form : 'userForm', //The specified form
success : function(response, options) { 
var o = Ext.util.JSON.decode(response.responseText); 
alert(o.msg); 
}, 
failure : function() { 
} 
}); 
} 
 
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 : ' The user name ', 
name : 'userName', 
allowBlank : false 
}, { 
fieldLabel : ' The secret   code ', 
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 : ' determine ', 
handler : function() { 
var form = formPanel.getForm(); 
var userName = form.findField('userName').getValue().trim(); 
var password = form.findField('password').getValue().trim(); 
if (!userName) { 
alert(' The username cannot be empty '); 
return; 
} 
if (!password) { 
alert(' The 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(); 
} 
 
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); 
} 
}); 
} 

Related articles: