< form>行动不是相对的
这是一个非常基本的问题:D
我在localhost/book上有一个html,其中具有
<form action="d" method="get">
<input name="q" placeholder="Book name"></br>
<button type="submit">Search</button>
</form>
- 与当前URL相对的d动作,
d动作,哪个localhost/book,对吗? ,因此单击搜索应该像
localhost/book/d?q =某些+数据
相反,但是,它就像
localhost/d?q = some+data+data
。我如何使其转到
localhost/book/d
This is a pretty basic question :D
I have an HTML at localhost/book which has a form,
<form action="d" method="get">
<input name="q" placeholder="Book name"></br>
<button type="submit">Search</button>
</form>
The d action meant to be relative to current URL, which localhost/book, right?
, so clicking Search should go likelocalhost/book/d?q=some+data
But instead, it goes like
localhost/d?q=some+data
.How do I make it goes to
localhost/book/d
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个URL问题:因为您的当前URL缺少尾随的斜杠(/),所以URL的最后一部分不被视为文件夹,而是“文件”。因此,如果您提交表格,则在您的情况下将继续升级。
一种解决方案是在URL中添加后斜线。这可以通过在网络服务器级别上重写来完成。或者,您可以更改链接,但是在这种情况下,如果访问者正在键入斜线,则永远不会安全。
更安全的解决方案将不在形式的作用中使用相对URL。
This is a URL-Issue: Because your current URL is lacking a trailing slash (/) the last part of the URL is not treated as a folder but a "file" instead. So if you submit the form it will go on level up in your case.
One solution would be to add a trailing slash in the URL. This could be done by rewrite on web-server level. Or you could change the link, but in that case you are never safe if the visitor is typing a slash or not.
The safer solution would be not to use a relative URL in the action of the form.
有关与父目录相关的,请使用
action =“ ../ D”
For being relative to parent directory, please use
action = "../d"