I'm trying to retrieve data from another server (testing locally) by calling a specific function within a PHP file. Currently nothing is being returned unless I manually call the function in the PHP file.
$.ajax({
type: 'POST',
url: 'http://test.local/php/ajax/json.php',
dataType: 'jsonp',
data: {action: 'get_data'},
success: function(data) {
$json = $.parseJSON(data);
[...]
}
});
My PHP is as follows, and evidently $_POST
is not set as the client application receives no data. Setting $_POST['action'] = 'get_data';
manually or calling get_data()
in the PHP file returns all the data fine.
if (isset($_POST['action']) && !empty($_POST['action'])) {
$action = $_POST['action'];
switch ($action) {
case 'get_data': get_data(); break;
}
}
Why is $_POST['action']
not being set by the AJAX query? Any help is appreciated.