I'm creating a web-based application that interfaces with a MySQL database on the same server. I'm using Javascript/jQuery to form the query, and then trying to use php to query the database.
Currently, I'm just trying to learn AJAX requests and php (testing on my local computer). Particularly, I'm trying to "alert" the result of my php code and add that to a div. But instead, I get an alert with the raw php code and my div is just blank. (This isn't the case if the url was set to a normal text file instead).
How can I make it such that the callback's variable called "result" is set to the output of the php script?
Below is my jQuery code for the ajax request:
$.ajax({
url: 'getData.php',
data: queryString,
method: 'GET',
cache: false,
success: function(result) {
alert(result);
$('#dataTable').html(result);
},
error: function(jqXHR, textStatus, errorThrown) {
if(jqXHR.status == '500') {
alert('Internal server error: 500');
} else {
alert('Unexpected error');
}
}
})
And here's my simple php file:
<?php
echo "huh";
?>