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.