来自函数的PHP未定义索引通过jQuery发送

I am trying to make a function that will insert a html code (div) into a container, said div has an ID of the number of elements inside that container +1 (so when it adds the first it won't be 0). I am fairly (read 1 week) new to JS, jQuery and PHP so I am having trouble tyding up my code so it can do what I need.

Right now when I use the function it is displaying a undefined index error. The process the code should run is this:

  1. In one page I enter some data and click a Accept button which saves that data into a database (Done).

2.When I click the accept button it also call a function that creates the aforementioned div, this code is in another file and its called with:

<script src="js/createLabDiv.js"></script>

The code of function goes like this (most likely with error >.< )

function agregar("#btnAceptar") {
    var div = document.createElement('div');  //Creates div variable.
    div.id = querySelectorAll('lista > div').length +1; //assigns id to div based on elements inside the list
    var numero = div.id;  //I'll need this to display a specific set of info depending on the div id.                              

    '<div class="box">  // Code for the div.
        <p>Lab #'numero'</p>
        <p class="info"><a href="#" id="lnkInfo">Info</p></a>
        <p class="info"><a href="reservarLab.html">Reservar</p></a>
    </div>';

    document.getElementById('lista').appendChild(div); //Where it is isnserting it.
    var request = $.ajax({                //Here it gets muddy, I want to send this data to a php file so I can call it on my list.php
        url: "includes/functionsLabs.php",
        type: "post",
        data: {
            'call': 'createDiv',
            'pDiv':div,
            'pNumero':numero},        
        dataType: 'json',
    });
}

3.On my includes php file I have:(Again kinda murky)

function getLabs(){
    $idDiv=createDiv();
    $query = "SELECT bk.idlab , bk.capacidad, bk.carrera, bk.ubicacion FROM labs as bk   WHERE bk.idlab = $idDiv";
    $result = do_query($query);
    return $result;
}

function createDiv(){
    $idDiv = $_POST['pNumero'];
    echo $div = $_POST['pDiv']; 
    $result = $idDiv;
    return $result;
}

4.And lastly in a different page I have:

<div class="scroll-area" id="lista">
    <?php createDiv() ?>
</div>

Just in case, all of these pages contain the scrip for the js. and the includes for the php. Both of them are working with the data I entered into my database for testing purposes, also the add (agregar) button on the add.php IS inserting correctly the data from the form, the list.php page which includes the piece of code just above this wall of text is also working when displaying the data from one Lab I already added to the database, the reason I needed number above was that when I called this:

<div class="popUp1 hide" id="popUpCorrecto1">
    <div class="estiloPopUp">
        <span>Información de laboratorio</span>
        <span value="Cerrar" id="btnCerrar">x</span>
    </div>
    <?php displayLabs() ?>
    <input type="button" value="Eliminar" id="btnEliminar" onclick="eliminar()" />
    <input type="button" value="Modificar" id="btnModificar" onclick="window.location='modificarLab.html';" />
</div>  

It was displaying the info of all the labs in the databse, thus why I added the WHERE bk.idlab = #idDiv.

I am quite stuck right now, so any kind of help would be very appreciated, I will probably be able to reply until tomorrow cuz I think I feel kinda sick from staring at my monitor all day >.>

Thanks a lot in advance and best wishes!