I've been trying to send an array from PHP to javascript so I can display search results from a database. I have converted the array into JSON and now can't seem to retrieve it. I've never used AJAX but I have some people that work here that have and no one has been able to figure out the exact problem (granted not a lot of their time has been spent on it)
$(document).ready( function() {
var data = {};
$.ajax({
type: 'GET',
url: '../wp-content/plugins/advantage-geo/get_data.php',
data: "data",
dataType: 'json',
cache: false,
success: function(result) {
alert(result.d);
console.log(result);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus); alert("Error: " + errorThrown);
}
});
});
That is the call from the JS file. (It closes with }); but it wasn't being taken into the code block so I removed it.)
The following is the PHP
<?php
header("Content-type:json");
global $wpdb;
$sql = "SELECT * FROM wptest_geo_db";
$result = $wpdb->get_results($sql) or die(mysql_error());
echo json_encode($result);
print_r(json_decode($person_array));
print_r($person_array);
?>
The JSON is created properly and I can display that on the page from the php file. The AJAX call is throwing an 500 Internal Server Error and I don't know why.