Hi iv got this error on my ajax function using json on retrieving data. It wont return any data. Here's my code below
$.ajax({
url: "php/getCategory.php?action=getyear",
cache: false,
dataType: "json",
success: function(data){
$.each(data.items, function(i,item){
$("#catYear").append('<option value="'+item.id+'">'+item.name+'</option>');
});
}
});
When i try to remove dataType: "json" it will pass into success: function. I think the problem is on my json. I also echo the output of my getCategory.php and i think their is no problem on it. Below is the output of my php json_encode.
{items:[{"id":"1","name":"2010"},{"id":"2","name":"2011"}]}
Thanks!
json_encodewill give you a lump of JSON. You still need the to sayheader('content-type: application/json');otherwise PHP will claim it is sending an HTML document.