从 JavaScript Online 访问客户端的“本地主机" [英] Accessing Client's 'localhost' from JavaScript Online

查看:19
本文介绍了从 JavaScript Online 访问客户端的“本地主机"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想要做的.

  1. 我制作了一些包含 JavaScript 代码的 .html 页面,并将它们托管在 Yahoo 服务器上.

  2. 现在,当具有特定浏览器的客户端查看这些网页时,JavaScript 代码使用 XMLHTTPRequest 在 h1ttp://localhost:8080/myservlet/servlet1 建立连接以读取一些数据.

  3. 我知道,我想连接到客户端计算机上运行的 Web 服务器,如果客户端有一个,即我在我的 xmlHTTPRequest 中使用 localhost.

但是,即使客户端在端口 8080 上运行 Web 服务器,这也不起作用.在客户端的计算机上,我可以访问 http://localhost:8080/mysevlet/servlet1 并且 servlet 是运行良好,但通过 Yahoo 服务器上托管的 .html 页面无法正常工作.

我在这里做错了什么?

解决方案

跨站脚本

一个>

您无法访问不在您域中的内容,除非它是返回 XML 或 JSONP 的 Web 服务

this is what I am trying to do.

  1. I have made a few .html pages with JavaScript code in it and hosted them on a Yahoo server.

  2. 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.

  3. 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.

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?

解决方案

Cross-site Scripting

You cannot access what is not on your domain, unless it is a Web Service returning XML or JSONP

这篇关于从 JavaScript Online 访问客户端的“本地主机"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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