如何使用Javascript/Ajax但不使用jQuery获取远程URL的状态代码? [英] How to get status code of remote url using Javascript/Ajax but NOT using jQuery?

查看:66
本文介绍了如何使用Javascript/Ajax但不使用jQuery获取远程URL的状态代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在不使用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.

请帮助.

谢谢.

推荐答案

使用

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的状态代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆