I am getting the error "[Error] ReferenceError: Can't find variable: data" when trying to get JSON data with AJAX / jQuery request.
I have an index.html file which loads jQuery and tries to get data from an ajax.php file.
CONTENT of index.html
$.ajax({
url : 'ajax.php',
type : 'POST',
data : data,
dataType : 'json',
success : function (result) {
alert(result['ajax']);
},
error : function () {
alert("error");
}
});
CONTENT of ajax.php
$someVariable = array(
'ajax' => 'Hello world!'
);
echo json_encode($someVariable);
Accessing ajax.php through the browser displays the data correctly:
{"ajax":"Hello world!"}
What am I missing? Thanks.