How to get HTTP status code of another site with JavaScript?
相关问题
- Angular RxJS mergeMap types
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
I assume JavaScript, with JQuery, which simplifies AJAX requests alot, like this.
You can't do this with AJAX directly because of the same origin policy.
You'd have to set up a proxy service on your server then make ajax calls to that with the address you want to check. From your server proxy you can use cURL or whatver tool you like to check the status code and return it to the client.
Try the following piece of javascript code:
You will have to use XMLHTTPRequest for getting the HTTP status code. This can be done by making a HEAD request to the server for the required url. Create an XMLHTTPRequest object - xhr, and do the following
See here for more details.