0

I have a very simple code that when the document is ready it tries to get some data using jQuery's get():

 $(document).ready(function() {
        startGetting();
    });

    function startGetting(){
        console.log("entering");
        $.get('prediction.pl', function(data){
            console.log(data)
        });

    }

My expected results on the console are:

entering
>data

but for some reason no data is being returned or anything.

If I execute the get() function straight in the console it does print out data. Any ideas why it doesn't work when called from the code, but does work when run from the console?

EDIT:

I noticed that if I change startGetting() to:

 function startGetting(){
        console.log("entering");
        foo=$.get('prediction.pl', function(data){
            console.log(data)
        });
  console.log(foo);
  }

Now foo has the data I want. But I have no idea why is this happening, any ideas?

4

0 回答 0