I would like to send a data via jQuery ajax
function to the PHP script and receive a response - success or failure. The code I am using:
JavaScript:
$.ajax({
type: 'POST',
url: 'foo.php',
dataType: 'json',
data: {
foo: 'foo'
},
success: function (response) {
...
},
error: function (response) {
...
}
});
PHP:
<?php
header("Content-Type: text/json");
echo $_POST['foo']
?>
However this always return error, because of header("Content-Type: text/json");
.
What is done wrong here?