【问题标题】:ajax POST, trying to add the directory link adds the path twiceajax POST,尝试添加目录链接添加路径两次
【发布时间】:2021-09-01 21:52:56
【问题描述】:
            $.ajax({
                type: "POST",
                url: "/bbr-category-configuration",
                data: "category_data",
                dataType: "json",
                success: function (response){
                    console.log(response);
                }
            });

我在 console.log 中测试我的 ajax 表单

它说 404 not found 但我想好吧,我错过了完整路径,所以我添加了:

url: "clinical/bbr-category-configuration",

这一次,路径通过我的clinical 文件夹两次,如下图所示

这是怎么回事? (目录被添加了两次)

【问题讨论】:

  • 在临床前尝试/clinical/bbr-category-configuration/
  • 第一个 url 以 / 开头,因此它从您网站的根目录/顶部开始,第二个不以 / 开头,因此它从脚本运行的文件夹开始 -我假设是clinical,所以clinical 出现了两次。要么用/ 开始你的第二个,要么从第一个中删除前导/
  • 我明白了,谢谢
  • 您能发布您的web.php 路线吗?所以我们可以指导你正确的道路

标签: ajax laravel forms post


【解决方案1】:

你定义的是url的绝对路径和相对路径。

在 JS 或 html 文件中,如果您使用 /urlPath 重定向/请求到任何 url,那么您的重定向/请求将从基本 url(http://example.com/urlPath) 开始。

您可以通过简单的锚元素看到这种行为。把这些放到html文件里就可以看到结果了

<a href="clinical/bbr-category-configuration">Redirects from the current path</a>

<a href="/clinical/bbr-category-configuration">Redirects from the base url path</a>

上述clinical/bbr-category-configuration 将从您当前的网址重定向/请求。如果您在 https://example.com/url/url2 上,那么您将转到 https://example.com/url/clinical/bbr-category-configuration

所以在你的情况下,你应该使用@Aless55 提到的/clinical/bbr-category-configuration

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 2023-04-09
    • 2022-12-17
    • 2011-11-11
    • 1970-01-01
    相关资源
    最近更新 更多