0

i have some problem with jQuery ajax request. when i try to do:

$vertices = getVertices();
console.log(getVertices());

and my function:

function getVertices() {
    $.ajax({
        method: "GET",
        url: "graph/vertices"
    }).done(function(data) {
        return data;
    });
}

I got undefined, and my ask is why do I get undefined ?

gargi258
  • 829
  • 1
  • 10
  • 16
  • Using Google chrome dev tools, what is the network pane saying to your request? – Samuel Jul 11 '16 at 16:25
  • Do you call the function before it is defined? Have you loaded jQuery correctly? – Samuel Jul 11 '16 at 16:27
  • 1
    @Samuel - no, the OP is returning data from an asynchronous function, which can't be done, see the duplicate. Also, the function is called twice in the example above, not that it matters. – adeneo Jul 11 '16 at 16:28
  • I put function on the top, call ony once andIt's still undefined, respons is properly. – gargi258 Jul 11 '16 at 16:53

0 Answers0