javascript - 我应该在我的网站中使用哪个路径?相关路径绝对路径?
问题描述
我正在为我的客户建立网站。我想知道我的网站应该使用哪个路径?哪条路径更安全?如果我完全错了,或者您有其他网站安全问题的原因,也请纠正我!提前致谢。
例如...
<script src="https://example.com/admin/js/myjavascript.js"></script>
or
<script src="/js/myjavascript.js"></script>
<img src="https://swadtiffin.ca/wp-content/uploads/myimg.jpg" alt="Loading...!">
or
<img src="/wp-content/uploads/myimg.jpg" alt="Loading...!">
$http({
method: 'POST',
url: '/wp-content/themes/astra-child/php/get_all_food_combos.php',
data: $.param({ 'data': "test" }),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function (resp) {
console.log(resp.data); //all items
});
}, function (error) {
console.log(error);
});
or
$http({
method: 'POST',
url: 'https://example.com/wp-content/themes/astra-child/php/get_combos.php',
data: $.param({ 'data': "test" }),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function (resp) {
console.log(resp.data); //all items
});
}, function (error) {
console.log(error);
});
解决方案
你的两种方式都可以。安全也不例外。但在不同的场景中使用。
如果您为服务添加 URL 前缀。
(https://example.com/wp-content/...php)
这意味着您只能从此 URL 获取数据。如果您在另一个网站上运行服务,则必须以这种方式进行。如果您不添加前缀,它将自动在您的本地路径中使用服务。
推荐阅读
- java - JUnit 并检查字段是否为空
- php - 在线时网站工作错误,但在本地 XAMPP Server + Mikrotik 路由器中工作正常
- ansible - 如何在 Ansible `find` 模块中使用通配符路径?
- xpages - Dojo Charting 中的工具提示出现在图表之外
- arduino - 为什么在 AVR 架构中有几个阶段来启用引脚更改中断
- spring-data - 带有 Guava 缓存 + Spring Data + Couchbase 索引文档的 TImoutexception
- react-native - 为什么占位符文本未在 react-native 中显示 textInput 字段?
- tensorflow - Tensorboard“计算时间”总结错误
- r - 使用包中的单个函数
- python - 如何使用 python 请求将电子邮件发送到本地电子邮件服务器