欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 前端技术 > HTML >内容正文

HTML

html页面怎么解决跨域问题,前端web开发html如何避免js的跨域访问

发布时间:2025/3/15 HTML 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 html页面怎么解决跨域问题,前端web开发html如何避免js的跨域访问 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

今天开发几个页面,但是页面中调用了线上的一些http接口进行渲染页面,因为跨域问题,但是又不想弄成jsonp方式,因此弄个apache http server来折腾。这个只适用于linux

1.从apache下载apache httpd

2.下载安装后打开安装目录下conf文件夹的httpd.conf配置文件进行修改

3.首先修改Listen端口比如为8081,修改之后保存(因为可能默认的80端口被占用了,所以修改自己定义的)

Listen 8088

4.打开安装目录下bin文件夹的httpd启动

./httpd -X

5.打开浏览器输入localhost:8088,可以发现会出现It works!提示,这说明启动成功了

但是如果我需要换成我的一些静态html页面和js等,比如我有一个静态页面项目webapp,我放到/usr/local/apache2/webapp(当然自己可以指定放到其他目录)

那么再打开httpd.conf找到如下

DocumentRoot "/usr/local/apache2/htdocs"

#

# Possible values for the Options directive are "None", "All",

# or any combination of:

#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#

# Note that "MultiViews" must be named *explicitly* --- "Options All"

# doesn't give it to you.

#

# The Options directive is both complicated and important.  Please see

# http://httpd.apache.org/docs/2.4/mod/core.html#options

# for more information.

#

Options Indexes FollowSymLinks

#

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

#   AllowOverride FileInfo AuthConfig Limit

#

AllowOverride None

#

# Controls who can get stuff from this server.

#

Require all granted

将/usr/local/apache2/htdocs替换为/usr/local/apache2/webapp

DocumentRoot "/usr/local/apache2/webapp"

#

# Possible values for the Options directive are "None", "All",

# or any combination of:

#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#

# Note that "MultiViews" must be named *explicitly* --- "Options All"

# doesn't give it to you.

#

# The Options directive is both complicated and important.  Please see

# http://httpd.apache.org/docs/2.4/mod/core.html#options

# for more information.

#

Options Indexes FollowSymLinks

#

# AllowOverride controls what directives may be placed in .htaccess files.

# It can be "All", "None", or any combination of the keywords:

#   AllowOverride FileInfo AuthConfig Limit

#

AllowOverride None

#

# Controls who can get stuff from this server.

#

Require all granted

保存后,重新启动httpd再访问即可正常访问其他了。

总结

以上是生活随笔为你收集整理的html页面怎么解决跨域问题,前端web开发html如何避免js的跨域访问的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。