10 June, 2011

Ajax call using jQuery

As we all know many web applications are using ajax.
And really its magic of AJAX !!!
Here is the code how can we make ajax call in liferay :


jQuery.ajax({
url:'/html/portlet/journal/getData.jsp',
data: {
directoryIdParam: directoryId
},
dataType: 'json',
type: 'POST',
success: function(dataJson) {
alert(dataJson);
});

Now Create getData.jsp file with below code sample code :
you can use your own logic to fetch the data.

<%@page import="com.ext.portlet.productdirectory.service.http.ProductCategoryJSONSerializer"%>
<%@page import="com.ext.portlet.productdirectory.service.http.ProductDirectoryJSONSerializer"%>
<%@page import="com.ext.portlet.productdirectory.service.ProductCategoryLocalServiceUtil"%>
<%@page import="com.ext.portlet.productdirectory.model.ProductCategory"%>
<%@page import="java.util.List"%>
<%@page import="java.io.PrintWriter"%>

<% long directoryId=new Long(request.getParameter("directoryIdParam")).longValue(); PrintWriter writer=response.getWriter(); List productCategoryList =ProductCategoryLocalServiceUtil.getCategoryListByDirectoryId(directoryId);
writer.write(ProductCategoryJSONSerializer.toJSONArray(productCategoryList).toString());
writer.flush();

%>

And Now you will see How Ajax is easy with jquery and LifeRay !!!!!!!!

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...