how to call servlet from listener event JS function? | Community
Skip to main content
amangoyal15
New Participant
November 25, 2016
Solved

how to call servlet from listener event JS function?

  • November 25, 2016
  • 2 replies
  • 4371 views

I have two field in dialog  - Pathfield /  HTML5SmartImageField .

From Pathfield, i will select one page which would be having one image.

Now what i want is - once i select page from pathfield , that image will automatically rendered on my smartimagefield.

I used dialogclose listener to listen the pathfield, once the page got selected my dialogclose event listener JS would be called.

In that JS, i want to make call ajax to call servlet.

From that ajax, i would pass path of the page selected from pathfield to the servlet. In that servlet, i would manipulate that path and will get that image path from its JCR property.and then plan to return back to ajax on success.

But I dont know can i make ajax call from Listener JS?

If possible , please provide me some reference for this in which we are calling servlet in listener JS 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kautuk_sahni

Hi 

Please have a look at these helpx article:

Link:- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

    // Submitting Adobe Experience Manager form data to Java Sling Servlets

    Here we are cresting a custom sling servlet, that we will be calling from jquery AJAX call.

 $.ajax({
type: 'POST', 
url:'/bin/mySearchServlet',
data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,
success: function(msg){
 
        var msgId= json.id;
        var lastName = json.lastname;
        var firstName = json.firstname;
 
        $('#ClaimNum').val(msgId);
        $('#json').val("Filed by " + firstName + " " + lastName);
              });
        });

Here we are submitting the data, but we can also return the data as well.

I hope this would help you.

~kautuk

2 replies

kautuk_sahni
kautuk_sahniAccepted solution
Employee
November 28, 2016

Hi 

Please have a look at these helpx article:

Link:- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

    // Submitting Adobe Experience Manager form data to Java Sling Servlets

    Here we are cresting a custom sling servlet, that we will be calling from jquery AJAX call.

 $.ajax({
type: 'POST', 
url:'/bin/mySearchServlet',
data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,
success: function(msg){
 
        var msgId= json.id;
        var lastName = json.lastname;
        var firstName = json.firstname;
 
        $('#ClaimNum').val(msgId);
        $('#json').val("Filed by " + firstName + " " + lastName);
              });
        });

Here we are submitting the data, but we can also return the data as well.

I hope this would help you.

~kautuk

Kautuk Sahni
smacdonald2008
New Participant
November 25, 2016

See this AEM community artilce - it will point you in the correct direction: 

http://scottsdigitalcommunity.blogspot.ca/2014/03/creating-aem-component-that-uses.html

Hope this helps....