-3

I am calling rest api through jquery and i need to read the videoList value in javascript.

below my code,every time alert is saying undifined.

How to read videoList in javascript?

Buddhika Lakshan
  • 182
  • 2
  • 13
  • This is my code $(document).ready(function() { $.get('https://123/movies', function(data) { $("#videoList").data(data.entries); }); }); var list = $("#videoList").listview; alert(list); – Buddhika Lakshan Sep 19 '17 at 16:31
  • 1
    You should move the alert inside the success callback since alert will run before data is retrieved. – Thusitha Sep 19 '17 at 17:21
  • Put your code in the question, not a comment. –  Sep 20 '17 at 02:53

1 Answers1

2

I added your code into the ticket, and there are two issues to look at.

Here is your original code:

    $(document).ready(
        function() { 
            $.get(
                '123/movies';, 
                function(data) { 
                    $("#videoList").data(data.entries);
                }
            ); 
        }
    ); 
    var list =  $("#videoList").listview; 
    alert(list);

You have an extra semicolon in your parameters to "get()" (after '123/movies').

We can't see your HTML, which could provide a clue.

Also, because it is outside of "$(document).ready(...)", your code to fetch videoList and alert the result is running before the page finishes loading.

theGleep
  • 1,179
  • 8
  • 14
  • Why would this work? The alert is going to run before the Ajax call finishes. –  Sep 20 '17 at 02:54
  • That's exactly what I was saying. I pasted the original code because my edit had not been approved. – theGleep Sep 20 '17 at 13:39
  • The alert needs to be inside the success callback, not just inside the ready function. –  Sep 20 '17 at 13:50