I need to receive a value of JSONP async request. When I assigning “data” to global variable, I receive a empty object. Please, help me.
Now, I my code get
var url = "http://local/main/getEventData/" + event_id;
var script = document.createElement('script');
script.setAttribute('src', url);
document.getElementsByTagName('head')[0].appendChild(script);
var event_data = {};
function callback(data) {
event_data = data;
}
and JSONP
callback({name: 'John'})
PS Request absolutely works and I can display data variable via console.log(data)
Use the data when you get it, not (as I assume you are trying now) as soon as you’re requested it.