Data from post in ajax request works but PHP still says undefined index

This is pretty weird to me and I can’t seem to find what’s wrong.
I’ll elaborate on what I’m doing now.

  • I have this page called “categoriasCatalogo.php” where I want a navbar to appear, I have this navbar in another file named “navbar.php”.
  • I have an Ajax request sending the level of navbar I want and the catalog’s ID, it’s correctly routed and the navbar displays properly, the payload has the correct data and the correct names, but I get an error saying the navbarlv index is undefined. Which cannot be as both match and as I said, the navbar is displaying and working.
  • This aproach worked in another file without any issues, only difference being the other file is in the root folder like navbar.php.

I’ll provide some stuff that might be useful:

  • This is the Ajax request, executed on the document.ready function in the “categoriasCatalogo.php” file, located in the bottom part of the code, making sure the container that will hold the navbar exists.
const getNavBar = (idcat) => {
        let paquete = "navbarlv=2&idcatalogo="+idcat;
        $.ajax({
            type: "POST",
            url: "../navbar.php",
            data: paquete,
            dataType: "html"
        }).fail(function(respuesta) {
            //TODO: Modal fail
        }).done(function(respuesta) {
            document.getElementById("navbarlvl2").innerHTML = respuesta;
            
        })
    }
  • Var_dump returns this:
Notice: Undefined index: navbarlv in C:laragonwwwMcPDFnavbar.php on line 3
NULL
string(1) "2" 
  • Payload looks like this:
{
    "navbarlv": "2",
    "idcatalogo": "9"
}
  • The beggining of “navbar.php” looks like this, the catalog ID (“idcatalogo”) is requested within the function navbarlvl2() and it’s working:
require_once "config.php";
$navbarLV = $_POST["navbarlv"];
echo var_dump($navbarLV);



switch($navbarLV){
    case "1":
        navbarlvl1();
        break;
    case "2":
        navbarlvl2();
        break;
}

This is my very first post here, thanks a lot in advance and hope you’re having a nice day 🙂