Forum Discussion

Gursimrat's avatar
Gursimrat
Leader
11 years ago

Ajax call from Custom Component to another

Is there a way I can do the following:

 

1. Make an ajax call from Custom Component 2 to another Custom component 1, just like we do for endpoints?

2. or, if above is not possible, I was thinking if we can first call the Custom component 1 in an endpoint, and then make an ajax call to this endpoint from Custom Component 2, which will let me access the CC1, i.e. a workaround of scenario 1 above.

 

Any thoughts?

3 Replies

  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    Hi Gursimrat 

     

    it is not possible to Ajax call any component, but you can always do 

     

    <@component id="my_first_component"/> 

     

    in your second component.

  • NicoB's avatar
    NicoB
    Lithium Alumni (Retired)
    11 years ago

    Hi,

    you can call a component in this way:

     

    $.ajax("http://YOURCOMMUNITY/restapi/vc?[COMPONENT-ID]&restapi.response_template=[COMPONENT-ID]&param1=value&param2=value")
    .done(function(data) {
       //Do stuff with the component's HTML
    }

    Please note that param1 and param2 are needed only if your component declares parameters otherwise you can ignore them.

    Also please note that this will work only if the current user has rest api "read" permissions.

     

    Thanks,

     

    Nico

     

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    11 years ago

    Please note that if you want to use NicoB 's method - you may need to get in touch with Lithium Support for the instance to be configured to allow this.