How do I check the validity of a remote URL with javascript?
I know this will probably lead to a security breach, but is there a way in JavaScript to check the validity of a URL? This has to be done in the client, because I need to check whether the URL is accessible from it. Internal/external ne开发者_JAVA百科twork differences apply.
I have tried to use jQuery.ajax()
, but it won't work with remote servers, and also JSONP, but I can't expect a JSON response. In fact, I have to test any sorts of URLs, not only valid XML or JSON.
Basically, I need to check for a valid statusCode = 200
or similar, if possible.
Well, it seems it's indeed not possible, probably due to security issues.
The resolution to this in my case was to create a JSONP response in another server, and the script would simply make a request to it (JSONP allows cross-domain requests).
Thanks to all.
精彩评论