ajax POST, 试图添加目录 link 添加路径两次

ajax POST, trying to add the directory link adds the path twice

            $.ajax({
                type: "POST",
                url: "/bbr-category-configuration",
                data: "category_data",
                dataType: "json",
                success: function (response){
                    console.log(response);
                }
            });

我正在 console.log

中测试我的 ajax 表单

它说 404 未找到,但我认为没问题,我错过了完整路径,所以我添加了:

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

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

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

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

在 JS 或 html 文件中,如果您 redirect/request 使用 /url 路径 到任何 url 那么您的redirect/request 将从基数 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 将从您当前的 url redirect/request。如果你在 https://example.com/url/url2 then you will go to https://example.com/url/clinical/bbr-category-configuration

所以在你的情况下,你应该使用 @Aless55

提到的 /clinical/bbr-category-configuration