AJAX / PHP pass $ _GET and $ _POST?

0

Good night everyone, I have a PHP script that creates a table in which, on this page is run an ajax script and gives real time to see who is in the database ... in this table I have a delete button for each person and when clicking a variable is created $ _GET with the process number (eg searchstudent.php? usrdelete = 5382)

AJAX:

 $('#textbox').keyup(function(){
    $("#display_students").text('');
    var name = $('#textbox').val();
    if($.trim(name) != ''){
        $.post('../core/Query/students/student_search.php', {st_process: name}, function(data){
            $("#display_students").append(data);
        });

    }
});

PHP:

    <?php


if(isset($_POST['st_process']) === true && empty($_POST['st_process']) === false){
    include("../Query-core.php");
    include('../db.php');

        $authentication = new DBRequest($host = 'localhost',
                                $user = 'root',
                                $pass = '',
                                $db = 'contas');

        $selectedstudents = $authentication->selectionQueryLike("alunos", $authentication->e(trim($_POST['st_process'])), "student_process");

        if(mysqli_num_rows($selectedstudents) > 0){
            echo "<table><tr><th>Nome</th><th>NºProcesso</th><th>ID</th><th>Apagar</th></tr>";

            while($row =  $selectedstudents->fetch_assoc()){
               echo "<tr>";
               echo "<td><a href='#'>" . $row["student_name"] . "</a></td>";
               echo "<td>" . $row["student_process"] . "</td>";
               echo "<td>" . $row["student_ID"] . "</td>";
               echo "<td><a href=?usrdelete=" . $row["student_ID"] . ">Delete<a/></td>";

               echo "</tr>";

            }
            echo "</table>";
    }   
}

?>

How could I pass both $ _GET and $ _POST in ajax simultaneously?

    
asked by anonymous 26.02.2018 / 22:21

1 answer

2

In this way:

$.post('../core/Query/students/student_search.php?usrdelete=5382', {st_process: name}, function(data){
    $("#display_students").append(data);
});

If you use the value of a variable, simply concatenate the string using the + sign, for example:

var variavel = 5382;

$.post('../core/Query/students/student_search.php?usrdelete=' + variavel, {st_process: name}, function(data){
    $("#display_students").append(data);
});

GET is all that goes in the querystring, ie in the URL after the sign of ? and POST is all that goes in payload ( body of > HTTP request ), then the POST HTTP statement combined with GET would look like this:

POST /pagina.php?getfoo=getbar HTTP/1.1 <--- aqui vai o GET (após o sinal de ?)
Host: foo.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 31 <--tamanho do body

postfoo=postbar&postbaz=postboo <-- body que contém o POST
    
26.02.2018 / 22:30