使用http打开本地html页面进行测试 [英] Open local html pages using http to test

查看:3969
本文介绍了使用http打开本地html页面进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  XMLHttpRequest无法加载file:/// C:\Users\Tordah\Desktop\foobar.xml。只有HTTP支持跨源请求。 

&

Uncaught NetworkError:未能在'XMLHttpRequest'上执行'send':无法加载

我相信我得到这个错误是因为HTML文件是通过 file:协议访问的,而不是 http:协议,它与XMLHttpRequest产生兼容性问题(这是一种猜测) 。我想知道是否有任何使用http协议测试我的网页的方法只能用于本地机器(因为只有在此项目的后期我才能访问服务器,因此该应用只能使用http工作,但现在我希望能够正确测试它)。



是否有任何workarrounds,我可以在本地计算机上执行,并且可以使用三种浏览器 IE ,Firefox和Chrome浏览器?



谢谢。

解决方案

我假设你没有安装本地服务器......我建议你XAMPP,是做这种东西的最佳选择......



https://www.apachefriends.org/download.html



这里是你可以下载它的网址。当您已经安装它时,您必须将您的工作复制到目录中。



C:/ xampp / htdocs /(在这里粘贴您的作品)



打开你的浏览器并写入这样的网址:

  http:// localhost: 8080 /(你工作目录的名称)/(你想要查看什么档案,如果有索引则更好)


I am coding a webapp and i get this kind of errors with chrome :

XMLHttpRequest cannot load file:///C:\Users\Tordah\Desktop\foobar.xml. Cross origin requests are only supported for HTTP. 

&

Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 

I believe i get this error because the HTML file is accessed with file: protocol and not http: protocol which creates compatibility issues with XMLHttpRequest (That's a guess). I would like to know if there's any ways of testing my pages using http protocol only with my local machine (because only later in this project i will have access to a server, and therefore the app will only work using http, but for now i would like to be able to test it properly).

Is there any workarrounds that i could do on a local machine and that could with with the three browsers IE, Firefox and Chrome?

Thanks.

解决方案

I assume that you didn't install a local server...i suggest you XAMPP, is the best for doing this kind of stuffs...

https://www.apachefriends.org/download.html

here is the url where you can download it. when you already install it, you have to copy your work into the directory

C:/xampp/htdocs/(here you paste your work)

open your browser and write in the url like this:

http://localhost:8080/(name of your work directory)/(what archive you want to see, better if it has index)

这篇关于使用http打开本地html页面进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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