我可以使用 JavaScript 评估远程服务器上 URL 的状态吗?即使我没有获得文档的实际内容,它是否被视为跨域引用?
如果通过纯 JavaScript 无法实现,我可以在 iframe 中加载文档吗?
我想做的是检查HTTP状态代码是否为200以及Content-Type是否为text/xml,以确保用户输入的URL有效。
顺便说一句,我正在使用 YUI。
最佳答案
Can I evaluate the status of a URL on a remote server with JavaScript?
不在标准浏览器安全上下文中(除非您另有说明,否则我会假设它,因为它涵盖了几乎所有用例)。
Is it considered a cross-domain reference even if I don't get the actual contents of a document?
是的。
If it's not possible through plain JavaScript, could I perhaps load the document in an iframe?
不可以,即使可以,您也无法访问 HTTP header 。
关于javascript - 使用 JavaScript 获取 HTTP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2183066/