Skip to main content
Level 9
Feb 11, 2016 10:37 AM UTC
Solved

Ajax call to servlet in sightly

Hi All,

I am struggling for the past two days with the issue mentioned below :

1] I have a component.html and I have the below section[to call js]

<script>
    $(window).load(function() {

        getData();
    });
    </script>

2] I have component.js file with the below section

function getData() {

$.ajax({
         type: 'GET',    
         url:'/bin/customservlet',
         success: function(msg){
           var json = jQuery.parseJSON(msg); 
            var msgId=   json.id;
            var lastName = json.lastname;
            var firstName = json.firstname;
              
            $('#ClaimNum').val(msgId); 
            $('#json').val("Filed by " + firstName + " " + lastName);   
         }
     });
}

Issues I am facing 

a] When I write the ajax call in component.html it works fine, but if I have that in a seperate js and call, the servlet is not getting invoked.

b] Once the above is done, I have to send a property via the above Ajax call to servlet. That property is available to me in component.html file in the form of ${xyz.selectors}[the property was retrieved via Java use class]

Just an FYI : The AJax call is not completely written yet.

I am struggling here for quite some time. Any thoughts/pointers on this will be really helpful.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Mani_kumar_
Mani_kumar_Accepted solution
Community Advisor
Feb 12, 2016 7:11 AM UTC

Hi All,

This may me useful for community people i tried something linke this to have an ajax call in servlet please find post on my blog

http://learneasycodeeasy.blogspot.in/2016/02/ajax-call-in-sightly-component.html

Thanks,

Mani Kumar K

16 replies

askdctmAuthor
Level 9
Feb 14, 2016 5:01 AM UTC

Hi Scott/Jitendra/Lokesh/Edubey/Mani,

Thanks a lot for your help.

Translate
GK-007
Level 9
Jun 13, 2016 6:44 PM UTC

This link is not opening.Could you please provide correct link if you have.

I am seeing the similar issue.

Translate
GK-007
Level 9
Jun 14, 2016 10:42 AM UTC

I am seeing similar issue where my servlet is calling and returning json file but my json is not able to be parsed and load the results.

I don't see any errors in error.log.

Any idea??

Thanks,

Kishore

Translate
GK-007
Level 9
Jun 14, 2016 6:59 PM UTC

Got the solution!!

Translate
Level 2
Jul 14, 2017 6:41 PM UTC

Link is broken

Translate