Using ajax inside the Web Content Display Portlet - ajax

I am using the liferay community edition 6.0. One of the pages will be using only the Web Content Display portlet to add content to it. I want to achieve the following inside that content i will load some html links that will be used to download some pdf. I want to add an ajax call to me domain before the actual redirect to the link has been done.
My question is the following. I've used the hook feature of liferay to add a java script ajax function in to the view.jsp. The click event is caught in the view.jsp but since there is no controller i don't know how to propagate this event to the domain.
So far i've done this function on my custom create portlet that are done using Spring MVC. But for this specific portlet i cant seem to find the controller or what ever handler the Web Content Display is using(if any).
Can someone please tell me if this is possible and point me in some direction if it is possible.

I am not sure what functionality you're trying to implement here, but I'll try to help. You can make an Ajax call to another jsp in your hook from your view.jsp.
jQuery.ajax({
type: "POST",
url: "/jsp/path/your.jsp",
data: "country="+country,
success: function() {
...
}
...
});

Related

Refreshing a single portlet in Liferay

I have a problem with refreshing a single Liferay portlet. I wrote a bit of javascript code to refresh a single Liferay portlet every 120s:
function refreshPortlet() {
Liferay.Portlet.refresh("SOME_KEY")
};
setInterval("refreshPortlet()", 120000);
It works fine and the portlet refreshes, but the problem is that content of the portlet does not. I tried to clear the cache of the portlet with WebCachePoolUtil:
function refreshPortlet() {
WebCachePoolUtil.remove("SOME_KEY");
Liferay.Portlet.refresh("SOME_KEY")
};
setInterval("refreshPortlet()", 120000);
But now the function does not execute at all. Any hints?
Thanks in advance,
Stjepko
WebCachePoolUtil is a Java class, thus not available on the JS side. The reason the method is not executing is that it's running into the unavailability of that class.
If you want to execute browser-side code like you did, you'd need to identify where caching is done - e.g. on the browser or on the server. Observe your Developer Tool's network tab and inspect what's going across the wire.
Depending on the portlet that you're trying to refresh - specifically if it's a custom portlet - I'd recommend to implement Ajax explicitly and refresh either from a REST API or through the portlet's serveResource method.

WFFM MVC add javascript onclick when Submit

I'm currently trying to trigger dataLayer push events on submit for wffm mvc form. There are a couple of sources I've found and none of them has worked so far for MVC. The closest to what I could work with is combining what I've gathered with these two links Sitecore WFFM: act on success and Trigger Google Analytics Events on Sitecore Web Forms
Currently, I'm stuck on trying to output the form's success message since wffm mvc does not have Form.SuccessMessage(or as far as I know).
For webforms it's like this:args.Result = args.Form.SuccessMessage + script;
Any help would be much appreciated.
datalayer where trigger on html element push using javascript. for example:
Your html element on show ,you want to push datalayer.
$('#loading').on('shown.bs.modal', function () {
dataLayer.push({ event: 'modalShowSuccessGoogleTy' });
});
ı hope this example can be helped you.

Add Live Support section to mvc 3 project

Greeting to the community. This is my very first question.
I had in mind to add Livezilla live support in my MVC website, but I realised that there are some problems.
First of all, it is written in php and mysql, so is it possible to comply with MVC and sql server?
Does anybody know a similar solution (like livezilla) in my case?
PS. Excuse my poor english...
you could even look into using an iFrame to run livezilla inside of an mvc3 page if you wanted.
or, you could roll your own. if you wanted to try implementing a live response mvc3 page look into jquery and ajax asynchronous calls such as $.post and also look into the extension for controller AsyncController, and [AsyncTimeout(XXX)]. you will also have to read up on sending and receiving json objects in ajax and from a controller to the view.
Simple psuedo:
View:
setTimeOut calls a javascript function every X milliseconds
the javascript function uses json to wrap page data and pass it to the controller inside a $.post() call
Controller:
recieves page data as an model object in a post
determines if page is out of sync or not
returns relevant sync data in a json object back to the view
View:
the same javascript function receives the json object from controller
updates the page based on relevant sync data
Problem solved. I just uploaded the folder given from livezilla in the root folder of my website. Then the only need to met is to have a Mysql server to create the database for livezilla. After that php and mvc runs together with no problem.

Load content via ajax in plone page

I'm working on a website which has been developed in plone. Now I'm facing an issue, I would like to load certain content from a template via an ajax call on normal Plone page(on some event trigger).
Do I need to create any python script??If yes where has it to be placed? and moreover how do I integrate it with TAL(I guess that would be needed) but I'm not sure how.
Could anyone guide me on this with necessary pointers/docs that I should look into?It would of great help to come over my issue and get things rolling.
Thanks,
Avinash
In the "Plone Developer Documentation" there's a section for Javascripting in Plone that perfectly fits your needs
Your question is a bit vague:
From your question, it seems that you just want your ajax call to return html to populate data on the page somewhere then?
Also, it sounds like you want to do the development TTW in the ZMI? Most developers would would use an add-on product and return your ajax response.
However, you can do it TTW with page templates just fine.
Create the new page template
populate it with the template code that gives you the desired output when called within the context of content on a site. For example, http://mysite.com/plone/page/my-template
in your javascript, use a url that in the ajax call: $.ajax({url: 'http://mysite.com/plone/page/my-template', success: function(data){ $('#content').append(data);}})
It's not really anything special to do ajax within plone--just use the tools available and piece it together.

Live Search using ASP.NET MVC and AJAX

I am looking to implement a live search in my MVC app similar to this site when you type in a question and results come up that are similar or like the search on http://www.krop.com/
I have the search code all working and results updated. I just need to know how to add the AJAX to the MVC framework (I know this site was built using it) so that when I type the results are updated.
I had this all working in normal ASP.NET Forms app.
what you need to do it attach to Jquery onchage event handler, and then call some ajax method of jquery ($.load , $.ajax etc...) and the information from a specified controller. asp.net mvc controller can return json results so you can later manipulate it in your javascript code.
if you have any other questions go ahead and ask.
An ASP.NET MVC site will have AJAX and JQuery available by default.
Mike Bosch's Blog can give you some pointers on this

Resources