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
crossDomaindoesn't do what you think it does. It just disables extra headers that are added for same origin requests in case your same origin request gets redirected to a different origin.dataType: 'image/png',—dataTypedoesn't accept a MIME type as a value.