问题描述
这就是我想要做的。
-
我已经制作了几个包含JavaScript代码的.html页面并将它们托管在Yahoo服务器上。
I have made a few .html pages with JavaScript code in it and hosted them on a Yahoo server.
现在当某个浏览器的客户端查看这些网页时,JavaScript代码使用 XMLHTTPRequest
在h1ttp:// localhost:8080 / myservlet / servlet1上建立连接以读取一些数据。
Now when a client with a certain browser views these web pages, the JavaScript code uses XMLHTTPRequest
to make a connection at h1ttp://localhost:8080/myservlet/servlet1 to read some data.
我知道,我想要连接到客户端计算机上运行的Web服务器,如果客户端有一个,即我在我的xmlHTTPRequest中使用localhost。
I know, I want to connect to the web server running on the client's computer if the client has one i.e. I am using localhost in my xmlHTTPRequest.
但是,即使客户端在端口8080上运行Web服务器,这也不起作用。在客户端的计算机上我可以访问 http:// localhost:8080 / mysevlet / servlet1
并且servlet运行正常,但通过 .html
在雅虎服务器上托管的页面不起作用。
But this is not working even when a client has a web server running on port 8080. On the client's computer I can access http://localhost:8080/mysevlet/servlet1
and the servlet is running fine, but through the .html
page hosted on Yahoo server it does not work.
我在这里做错了什么?
Anything that I am doing wrong here?
推荐答案
您无法访问域中不存在的内容,除非它是返回XML或JSONP的Web服务
You cannot access what is not on your domain, unless it is a Web Service returning XML or JSONP
这篇关于从JavaScript Online访问客户端的“localhost”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!