Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send and receive data in same ajax request with jquery

Tags:

What is the best way to send data and receive a response dependent on that data?

Consider the PHP file used for the request:

$test = $_POST['test'];

echo json_encode($test);

I have tried unsucessfully to achieve this with:

$.ajax({
    type: "POST",
    dataType: "json",
    data: '{test : worked}',
    url: 'ajax/getDude.php',
    success: function(response) {
        alert(response);
    }
});