Load item with ajax

0

I'm doing some tests with ajax and php and I'm having a problem.

I proceed to comment:

I have a page antecedentes.php which has a button add categories, which calls the function in ajax add categories.

The function adds the category but the issue is that when you receive the data, I need you to load in .load the page antecedentes.php + la variable de usuario that created that category, since I have a SQL query in antecedentes.php that lists me categories according to idpersona .

The code of the function is like this:

function agregardatoscategoria(idpersona,nombre,descripcion){

cadena="idpersona=" + idpersona + 
        "&nombre=" + nombre +
        "&descripcion=" + descripcion;


        $.ajax({
    type:"POST",
    url:"php/agregarDatosCategoria.php",
    data:cadena,
    success:function(r){
        if(r==1){
            $('').load('antecedentes.php');

            alertify.success("agregado con exito :)");
        }else{
            alertify.error("Fallo el servidor :(");
        }
    }
});

In .load I would have to load antecedentes.php?id=idpersona but I do not know how to pass the variable.

I hope some answers and have raised my question well. Thank you very much!

    
asked by Santiago Gonzalez 15.09.2017 в 21:27
source

3 answers

0

Thank you very much for your cooperation. With load I was getting complicated, I managed to solve what I wanted in this way.

 window.location.replace("antecedentes.php?id="+idpersona);

I appreciate the altruism of the community! Salu2 !!

    
answered by 15.09.2017 / 22:46
source
0

If you check the JQuery documentation Load you will see that the function receives 3 parameters: url, data and the function that executes a once the load is completed. Then the variable should send it in the second parameter, being as follows:

 $('').load('antecedentes.php', {id: persona});

Then in antecedents.php you can capture the variable in the following way:

idPersona = $_POST['id'];

I hope you serve, greetings.

    
answered by 15.09.2017 в 21:56
0

It should be enough to send the parameter in the URL, like this:

$('#contenedor').load('antecedentes.php?id='+idpersona);
    
answered by 15.09.2017 в 21:39