I have the following code which generates a good json output but it has '[' and ']' at the start and end respectively. You can also check the output at
http://android.ezinfotec.com/functions.php?method=getquestions
$query = mysql_query("select * from questions");
$i = 0;
while($fetch = mysql_fetch_array($query))
{
$output[] = array (
"row".$i => array (
"id" => $fetch['id'],
"answers" => $fetch['answers'],
"status" => $fetch['ans_status'],
"postedon" => substr($fetch['month'],0,3).' '.$fetch['day'].' '.$fetch['year'],
"question" => $fetch['question'],
"category" => $fetch['category'],
"parent" => $fetch['parentcategory'],
"authorid" => $fetch['author'],
"authorname" => $fetch['author_name']
)
);
$i++;
}
echo json_encode($output);
Here is my html page which generate [Object object] when I try to get the data from the url
$(function() {
$('#getdata').click(function(){
$.ajax({
url: 'http://localhost:8080/android/functions.php',
type : 'GET',
data : 'method=getquestions',
dataType : 'json',
success : function(s) {
alert(s);
},
error: function(XMLHttpRequest,textStatus,errorThrown)
{
console.log(XMLHttpRequest+' '+textStatus+' '+errorThrown);
}
});
});
});
I think it is because of the '[' and ']' I'm not able to access data using ajax. IN the success function i get [Object object]