I'm not sure what I've done wrong with this but I have a php function that I need to retrieve some data from.
I am using JQuery 1.11 to execute an ajax function
$(document).ready(function() {
$('#butt_example').on('click', function() {
$.ajax({
url : 'scripts/functions.php',
type : 'GET',
dataType : 'json',
data : {
'action': 'test'
},
success: function(result) {
var la_result = JSON.parse(result);
console.log(la_result);
},
error: function(log) {
console.log(log.message);
}
});
});
});
Then I replaced my php function with a simple one just for testing
<?php
if(isset($_GET["action"])) {
$arr = array();
$arr[0] = "test";
$arr[1] = "passed";
header('Content-Type: application/json; charset=utf-8');
echo json_encode($arr);
}
?>
However when I click the button to execute the code I see that the console log result is undefined.
Why is this?
UPDATE
After Mike's comment bellow I realised that it's actually executing the console log in the error condition.
So it's failing somewhere and I'm not sure why