AUI Ajax Call and Periodic Refresh

Below code demonstrate how to use Ajax Call in your Liferay Code/Yahoo Code.



Example 2 : A Generic Method to Manage Your Ajax Calls

function ajaxPush(targetDiv, requestURL, postData, syncMode) {
	A.use('aui-io-request', function(A) {
		A.io.request(requestURL, {
			method : 'POST',
			cache: false,
			dataType : 'html',
			data : {
				postKey : postData
			},
			sync : syncMode,
			on : {
				start : ajaxPushStartEventManager(targetDiv),
				success : function() {
					ajaxPushSuccessEventManager(targetDiv, this
							.get('responseData'));
				},
				failure : function() {
					ajaxPushFailureEventManager(targetDiv, this
							.get('responseData'), requestURL);
				}
			}
		});
	});
}

Note : ajaxPushStartEventManager/ajaxPushSuccessEventManager/ajaxPushFailureEventManager These are callback methods and contains the start/success/failure of ajax call. Like in ajaxPushStartEventManager method you can put a loading Mask to the targetDiv and helps user to understand something is being loaded via ajax.

One thought on “AUI Ajax Call and Periodic Refresh

  1. Thanks bibek, Today I was searching related to the sync ajax call using alloy ui. so found your blog.. good to see..

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: