I’ve searched for hours trying to fix this jQuery/JS code, But It just doesn’t seem to want to return anything.
var result = getURLS(); // this is always blank
function getURLS() {
var urls = [];
var URL_record = Parse.Object.extend("URL_record");
var query = new Parse.Query(URL_record);
query.equalTo("user", Parse.User.current());
query.ascending("date");
query.find({
success : function(results) {
var tempURLS = [];
$.each(results, function(index, record) {
urls.push(record.get("shortURL") + " " + record.get("longURL"));
});
},
error : function(error) {
}
});
return urls;
}
Although if I create an alert function from this particular function:
success : function(results) {
var tempURLS = [];
$.each(results, function(index, record) {
urls.push(record.get("shortURL") + " " + record.get("longURL"));
});
alert(urls);
},
It seems to alert fine.
Any ideas?
query.find is asynchronous, you’ll need to set the variable inside of the success function then call the code that uses result.