这就是我想要做的.
我制作了一些包含 JavaScript 代码的 .html 页面,并将它们托管在 Yahoo 服务器上.
现在,当具有特定浏览器的客户端查看这些网页时,JavaScript 代码使用 XMLHTTPRequest 在 h1ttp://localhost:8080/myservlet/servlet1 建立连接以读取一些数据.
我知道,我想连接到客户端计算机上运行的 Web 服务器,如果客户端有一个,即我在我的 xmlHTTPRequest 中使用 localhost.
但是,即使客户端在端口 8080 上运行 Web 服务器,这也不起作用.在客户端的计算机上,我可以访问 http://localhost:8080/mysevlet/servlet1 并且 servlet 是运行良好,但通过 Yahoo 服务器上托管的 .html 页面无法正常工作.
我在这里做错了什么?
跨站脚本
一个>
您无法访问不在您域中的内容,除非它是返回 XML 或 JSONP 的 Web 服务
this is what I am trying to do.
I have made a few .html pages with JavaScript code in it and hosted them on a Yahoo server.
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.
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 访问客户端的“本地主机"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
NETWORK_ERROR:XMLHttpRequest 异常 101NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 异常 101)
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)