Foren

ajax call to serve resource..

Lucian Alexandrescu, geändert vor 9 Jahren.

ajax call to serve resource..

New Member Beiträge: 10 Beitrittsdatum: 16.04.14 Neueste Beiträge
Hi everyone!

I make this call from view.jsp and is working perfect..

<portlet:resourceurl id="addEntry" var="addUrl" />

<input type="button" value="Add Ajax Call" onclick="ajaxAddEntry('${addUrl}');">

function ajaxAddEntry(addUrl) {	
		
	jQuery.ajax({
 			type: 'GET',
			 url:  addUrl,
			 cache:false,
			 async:true,
			 error: function(){
						 alert('error');
				    },		
			dataType: "text",
			data :{
				data1: "123",
				data2: "456",				
 				},
 			success: function(status) {			
				 alert('response : ' + status);
			 }
		});
}



public class MyPortlet extends MVCPortlet {	

    @Override
    public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
    		throws PortletException {        	
    	
		 try {
			 String resourceID = resourceRequest.getResourceID();

			 if (resourceID.equals("addEntry")) {
				
				System.out.println("here test addEntry");
				
				addEntry(resourceRequest, resourceResponse);
			}
...

}


public JSONObject addEntry(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
			throws Exception {

          String data1 = resourceRequest.getParameter("bookmarkUrl");

}





How can I achieve the same result calling the method from portal theme?

Thanks in advance for any suggestion!
thumbnail
Pankaj Kathiriya, geändert vor 9 Jahren.

RE: ajax call to serve resource..

Liferay Master Beiträge: 722 Beitrittsdatum: 05.08.10 Neueste Beiträge
If you are asking about calling your portlet's serveResource method outside of your portlet, then use <liferay-portlet:resourceURL/> (using taglib uri "http://liferay.com/tld/portlet")

For example: <liferay-portlet:resourceURL portletName="NAMEOFPORTLET" var="addUrl"/>
thumbnail
Mohd Danish, geändert vor 9 Jahren.

RE: ajax call to serve resource..

Regular Member Beiträge: 187 Beitrittsdatum: 05.03.12 Neueste Beiträge
As far as I know you cant make ajax call from theme. To make ajax calls you need to have a portlet in your theme.
Make your ajax call from portlet, and embed it into portal theme.
thumbnail
N. Belo, geändert vor 5 Jahren.

RE: ajax call to serve resource..

Junior Member Beiträge: 33 Beitrittsdatum: 17.03.09 Neueste Beiträge

Well I think it's possible to make an Ajax Call from the Theme if you have defined a Friendly URL for a portlet and then do a POST or GET to that URL.
Don't you agree?