I want to edit a javascript variable based on whether or not a file exists. Can this be done using a callback function with an ajax get request? Here is a potential solution based on a suggestion from user Jonathan Crowe:
var url="Content/Features/column1.html";
var url2="";
function getURL2(callback) {
callback = callback || function() {};
$.ajax({
url: url,
error: function()
{
callback("something");
},
success: function()
{
callback("something else");
}
});
}
getURL2(function(url2) {
});
When debugging, url2 = "something" at the end of the
getURL2(function(url2) {
});
call. However if I try to access url2 outside of this function it is still set to "". How can I change the value of url2 based on the result of an ajax get request?
Thank you very much for taking time to help. Let me know if you need anything else from me.