Send and receive data in same ajax request with jquery
ajax, jquery, php
Solution
Lose the quotes to pass the object:
$.ajax({
type: "POST",
dataType: "json",
data: {test : worked},
url: 'ajax/getDude.php',
success: function(data) {
alert(data);
}
});
Problem
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); } }); ```