$.ajax async response usage


I have spent hours on this issue, which seems to trip up lots of newbies.

I am trying to test to see if a file exists and execute something if the file exists, and write to the console log the error if there is an error.

Thank you,


function UrlExists(filename)
  console.log("arrive in async function")
  var apple= $.ajax({
    type: "HEAD",
    async: false,
    url: filename
  return apple;