get() function returing string not JSON object.
I have a very simple PHP script that returns JSON like this:
-
{"question":"What day is it?"}
And I'm trying to call it from another page using Ajax. My code looks like this:
-
var url = "/test.php";
$.get(url,
function(data){
$.each(data, function(i, value) {
alert(value);
}, "json"
);
});
When I run it I get each character printed out one at a time in a separate alert. And then whenI used this line of code:
alert(typeof data);
it tells me that 'data' is a string. Shouldn't it be a JSON object? Any idea what's going on here?