the problem here is that I have a function that uses an ajax request to return a value to the myBookmarks variable. This variable needs to be assigned before the remainder of the JavaScript (not shown) can execute. So setting async: false does the trick, but in Firefox, I get:
Use of XMLHttpRequest's withCredentials attribute is no longer supported in the synchronous mode in window context.
I have been pursuing a solution using a setTimeout, but the anonymous function in the setTimeout cannot return the value of bookmarks to the upper level function.
So the question is, how to pause execution within the index() function and return the value of bookmarks back to the upper level myBookmarks var without using async: false?
var myBookmarks = index();
function index() {
var bookmarks = false;
$.ajax({
xhrFields: {
withCredentials: true
},
crossDomain: true,
async: false,
url: BOOKMARKS_URL,
contentType: 'application/json',
dataType: 'json',
success: function(data){
if (!data.errors) {
// INDEX SUCCESS
bookmarks = data;
} else {
// INDEX FAILURE
}
}
});
return bookmarks;
}