Im having a little confusion why the following is not working.
get.php
data
contains a string of the JSON, so arr[2]
will be the third character in the string. You need to use $.parseJSON(data)
.
Your PHP is claiming that the JSON is HTML. You need to explicitly say it is JSON to get jQuery to handle it as such automatically.
header("Content-type: application/json");
you can't gave the data value to the array.
$.get("get.php", function(data){
alert(data[2]);
}, "json");
Send the json header in php via header('Content-type: application/json');
so jQuery should automatically decode your json data.