I'm trying to return a value from an Ajax request, but I'm getting nothing in return. I want to return the user ID from the Instagram API so I can use it in other functions. I have put the Ajax call inside a function and added async: false, but all I get is the empty string.
function getId() {
var result = "";
$.ajax({
url:'https://api.instagram.com/v1/users/search',
dataType: 'jsonp',
type: 'GET',
async: false,
data: {
access_token: "ACCESS_TOKEN",
q:"unsplash"
},
success: function(data) {
result = data.data[0].id;
//alert(result);
}
});
return result;
}
var id = getId();
alert(id);