I am trying to validate an image URL if it still holds the image or not by making ajax call to that URL. One problem is the image server is on a different domain so I am using crossDomain:true attribute in my ajax call. Here is what I have tried so far:
function checkFunc(){
$.ajax({
url: 'https://www.google.co.in/images/srpr/logo11w.png',
dataType: 'image/png',
crossDomain: true,
timeout: 5000,
error: function(e, status, settings){
alert('ERROR: '+JSON.stringify(e));
},
success: function( e, xhr, settings ) {
alert('SUCCESS: '+JSON.stringify(e));
}
});
}
But its not working. Also a concern is the images are not confined to a single format, i.e. the image can be png/jpg/gif or any other so I need to have a broader dataType to accept any kind of image.
I have also tried using jsonp, but that gives me error as "Refused to execute script from because its Mime type(image/jpeg) is not executable.
Edit: I cannot run server script from my ajax function which in turn calls the cross domain page, as in php getcontents
You have to set up the image server to allow cross-origin requests. To do that you need to set the a Header on the server holding the images like this:
You can replace the * with your specific domain, in fact you should, otherwise anyone can do a cross-origin request on your image server.