Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Simple AJAX Request with params as array


If you need to pass parameters to ajax request, use a single array and then assign params: array like below:

var profItemLength = 0;
profItemLength 	= profileForm.getForm().items.items.length;
profData             = new Array();
profData['task']     = 'saveProfile';
profData['sid']     = SERVICE_SID;
profData['acc_id']     = ACCOUNT_ID;
profData['service_id']         = SERVICE_SELECTED;
profData['new_username']     = NEW_USERNAME;
for(var i=0; i<profItemLength; i++){
    var field_type = ''
	field_type = profileForm.getForm().items.itemAt(i).getEl().dom.type;
    if(field_type != 'button'){
	var field_id = '';
	    field_id = profileForm.getForm().items.itemAt(i).getEl().dom.id;
	var field_value = '';
	    field_value = profileForm.getForm().items.itemAt(i).getEl().getValue();
	if(field_type == 'checkbox'){
	    if (profileForm.getForm().items.itemAt(i).checked == true) field_value = 'on'; else field_value = '';
	}
	profData[field_id]     = field_value;
    }
}

Ext.Ajax.request({
    waitMsg: 'Saving profile...',
    url: 'account-processor.php',
    params: profData,
    callback: function (options, success, response) {
    if (success) {
	var json = Ext.util.JSON.decode(response.responseText);
	   Ext.MessageBox.alert('Add Profile Info', json.msg);
	}
	},
	failure:function(response,options){},
	success:function(response,options){}
    }
);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: