0

I'm getting a JSON from ASP.NET MVC controller and I want to use it inside a JS variable. I'm sure data is not null but it says myVar is null, here is my code :

        var myVar = null
        $(document).ready(function () {

            var myurl = "/SomeController/SomeAction";



            $.get(myurl, null, function (data) {
                myVar = data;
            });
        });
        var cy = cytoscape({

          container: document.getElementById("cy"),
          elements: myVar

        });

console.log(myVar); // returns null

How can I pass the content of data to cy object correctly? Thanks.

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
jason
  • 6,962
  • 36
  • 117
  • 198
  • See http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – Jasen May 01 '17 at 17:48
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Jasen May 01 '17 at 17:50

0 Answers0