使用 Windows 脚本宿主 (.hta) 的 HTTP 请求
我不敢相信我被困在这里,但我似乎无法使用 Windows 脚本主机或简单的 .hta 文件发出简单的 HTTP 请求。
这是我的代码:
<script language="Javascript">
window.onload = function() {
var http = CreateObject("Microsoft.XmlHttp");
};
</script>
当我启动 .hta 文件时,我收到一个 JavaScript 错误,上面写着 Object Expected
之类的内容。这非常烦人,因为这是一项微不足道的任务,而且我无法真正调试它。
知道如何调试这个东西吗?谢谢。
I can't believe I'm stuck here, but I can't seem to make a simple HTTP request using Windows script host or simple .hta file.
This is my code:
<script language="Javascript">
window.onload = function() {
var http = CreateObject("Microsoft.XmlHttp");
};
</script>
When I start the .hta file I get a JavaScript error saying something like Object Expected
.. this is very annoying since it's a trivial task and I can't really debug it.
Any idea how I can debug this stuff? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的函数只是创建对象然后销毁它。尝试返回外部变量或在函数中执行更多操作。
your function simply creates the object and then destroys it. Try returning to an external variable or doing more in the function.
在我看来,您应该在 .hta 文件中使用
or ,
而不是
CreateObject()
。更新:嗨卢卡!我在评论中没有太多地方,可以发布不太好的链接,所以我附加了我的答案:
您在问题代码中所做的错误是您尝试在 JavaScript 其他语言的元素中使用。在VBScript中存在CreateObject,但它是VBScript语言的一个功能。在 JScript/JavaScript 中,您必须使用 新的 ActiveXObject 来代替。
此外,您在评论中多次提到跨域问题,但从未描述过您是做什么的。如果您需要有关此主题的帮助,您应该在问题中包含有关您做什么的更多信息。也许您可以在 WSH 或 C 中包含有效的代码,并包含相应版本的 .HTA 文件。如果您描述为什么要使用 .HTA 文件而不是 WScript/CScript 或 PowerShell,也会很有帮助。您想在什么情况下使用.HTA文件?
It seems to me you should use
or just
inside of .hta file instead of
CreateObject()
.UPDATED: Hi Luca! I have not much place in comments and can post links not so good, so I appended my answer:
The error which you do from the code of your question is that you try use in JavaScript elements of other language. In VBScript exist CreateObject, but it is a feature of the VBScript language. In JScript/JavaScript you have to use new ActiveXObject instead.
Moreover you mentioned in your comments several times about cross domain problems, but never described what do you do. If you want a help about this subject you should include in your question more information about what do you do. Probably you can include code in WSH or C which worked and include the corresponding version of the .HTA file. It would be also helpful if you describes why you want to use .HTA file instead of WScript/CScript or PowerShell. In which scenario you want to use .HTA file?