问题描述
我正尝试在不使用jQuery或从该URL加载图像的方法的情况下,检查URL是否可访问或是否使用javascript.如果我可以获取该网址的状态码,那将是很好的,因为我只关心状态码为200.
I am trying to check if a url is reachable or not using javascript without using jQuery or the method of loading an image from that url. It would be great if I can get the status code of that url, because all I care about is that status code being 200.
我已经尝试过XMLHttpRequest,但是我了解到它不支持跨域调用.
I have tried XMLHttpRequest but I learned that it does not support cross domain calls.
请帮助.
谢谢.
推荐答案
使用服务器端语言,让此脚本返回状态代码.此代理"脚本将为您请求URL,因此无需进行跨域请求.
Create a server side script using a server side language, have this script return the status code. This "proxy" script, will request the URL for you, so that no cross domain requests need to be made.
有关Python响应代码脚本的示例,请参见此处:从URL获取HTTP响应代码的最佳方法是什么?
For an example of a Python response code script, see here: What’s the best way to get an HTTP response code from a URL?
希望有帮助,-Sunjay03
Hope that helps,-Sunjay03
这篇关于如何使用Javascript/Ajax但不使用jQuery获取远程URL的状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!