Thursday 11 February 2016

Ajax Call in Sightly component

How to make an ajax call in sightly component ???

Steps:

Follow the below steps to make an ajax call to a servlet in sightly.

1.Create a sightly component(Lets say it is component.html)
2.Create a file with name js.html under the component.
3.Write the required ajax method to invoke the servlet.
4.Include js.html in component.html

Code:

Component.html:

Here is the ajax html file included

<div data-sly-include="js.html"></div>

Js.html:

<script>
function invokeajaxCall() {
    $.ajax({
             type: 'GET',    
             url:'/libs/migration',
             success: function(msg){
alert('Method Success');
             }
         });
    }
    $(window).load(function() {

        invokeajaxCall();
    });
</script>

Component Structure:




3 comments:

  1. How to i send some parameters like dialog properties from sightly to this AJAX call.?

    ReplyDelete
    Replies
    1. Where exactly you are invoking call.Please tell me more on this.

      Delete
  2. Am using server-side JavaScript USE API to read the dialog properties like below
    use(function () {
    var myproperty = properties.get("renderpagetype");
    return { callajaxvariable: myproperty,
    };
    });

    and i need the "callajaxvariable" value to to call AJAX request. How to do it.?

    ReplyDelete