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

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

im testing out my ajax form in a console.log

1

it says 404 not found but I thought alright sure, I missed the full path so I added:

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

This time, the path goes through my clinical folder twice as seen in the next screenshot

2

How is this happening? (the directory getting added twice)

1 Answers

What you are defining are absolute and relative path of the url.

In JS or html file, if you redirect/request to any url with the /urlPath then your redirect/request will be from the base url(http://example.com/urlPath) onwards.

You can see this behaviour with simple anchor element. Just put these in the html file and you will see the result

<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>

The above clinical/bbr-category-configuration will redirect/request from your current url. if you are on https://example.com/url/url2 then you will go to https://example.com/url/clinical/bbr-category-configuration

So In your case you should use /clinical/bbr-category-configuration as mentioned by @Aless55

Related