Mystogan Mystogan - 2 months ago 10
Javascript Question

Check if file (ClickOnce) exists using jQuery

I am trying to find out whether or not a file exists, before trying to download it. The file is a ClickOnce application.

I have already tried the following code, but this does not work (maybe because the URL is on a different server and domain?);

$.ajax({
url: 'http://www.example.com/somefile.ext',
type: 'HEAD',
error: function()
{
//File does not exist
},
success: function()
{
// File exists
}
});


Is there another solution, or is there a means to get this one to work?

Answer

Yes, this should not work if the URL is on a different server. If you want to make this work, you will need control over the server where the URL is downloaded from. If so, you should set the Access-Control-Allow-Origin header to the name of the server from which your JavaScript is loaded.

See Stack Overflow question jQuery AJAX cross domain for more details.

Comments