View Full Version : Ajax call with out using a form.

3 Dec 2009, 7:23 AM

I have a button that when pressed will call a page via Ajax.
With only using ExtJS code, how can this be achieved. I am currently using HTTPProxy to call PHP pages when submitting forms and loading data into grids, but how can I perform HTTPProxy calls from just a simple button click (i.e. not a button linked to a form).


3 Dec 2009, 7:27 AM
Just use a simple ajax request: http://www.extjs.com/deploy/dev/docs/?class=Ext.Ajax&member=request

3 Dec 2009, 7:29 AM
Here is the pattern i use within a class, which includes multiple levels of checking

loadDepartment : function() {

var record = this.departmentListDV.getSelectedRecords()[0];
this.el.mask('Fetching data for ' + record.get('e'), 'x-mask-loading');

url : 'departments/getDepartment',
scope : this,
callback : this.onAfterAjaxReq,
succCallback : this.loadCenterPanel,
params : {
id : record.get('id')
onAfterAjaxReq : function(options, success, result) {
if (success) {
var jsonData;
try {
if (jsonData = Ext.decode(result.responseText)) {
options.succCallback.call(options.scope, jsonData);
else {
Ext.MessageBox.alert('Error!', 'Data returned is not valid data!');
catch (e) {
Ext.MessageBox.alert('Error!', 'Data returned is not valid data!');
else {
Ext.MessageBox.alert('Error!', 'The web transaction failed!');