If you’re trying to set a variable to contain the data from the call, then you’d set it after receiving data from the call. The jQuery ajax call is barebones, and you can instead us their JSON call to simplify your request: http://api.jquery.com/jQuery.getJSON/ You should refer to the jQuery documentation for how to handle responses from requests. They provide examples in their documentation.
You seem new to JS, so you should try reading a guide and following tutorials before attempting to create anything with it: https://developer.mozilla.org/en-US/docs/Web/JavaScript JavaScript is largely an asynchronous language that depends on callback functions to handle data passing from asynchronous event completion.