Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: ajax call to serve resource..
Hi everyone!
I make this call from view.jsp and is working perfect..
How can I achieve the same result calling the method from portal theme?
Thanks in advance for any suggestion!
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!
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"/>
For example: <liferay-portlet:resourceURL portletName="NAMEOFPORTLET" var="addUrl"/>
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.
Make your ajax call from portlet, and embed it into portal theme.
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?