I am trying to implement an ajax call to get some data from the server.
Earlier this data was hard coded into JS. So I am reducing the page load and get that data from the server. The data I am getting is used on many places on the page. 

Now I used both `$.ajax` and `$.getJson`.

```
$.getJSON(reqUrl)
.done(function(data){
    searchvars = data;
})

$.ajax({
    url: reqUrl,
    type: 'GET'
})
.done(function(data){
    searchvars = data;
})

```

In case of `$.getJson`, everything works fine. 
But in case of `$.ajax`, it gives error of "variable not found". Which means that the `$.ajax` request is late in getting data and assigning to the "variable".

My question is why `$.getJson` works perfectly and `$.ajax` doesn't. Also do you have any better approach to this problem ?

Thanks!