jquery - JSON response error in codeignitor -
i new in codeignitor framework , json. want fetch data database when user clicks on url, i'm getting error.
my script:
function abc(i) { if(i == 1) { $.ajax({ type: "post", url: "<?php echo base_url('welcome/liststd');?>", data: 'postdata='+ , success: function(json) { var abc = json; document.getelementbyid("fname").innerhtml=abc[0].fname; } }); } }
firebug response:
[ { "id":"31", "fname":"darshan", "mname":"d", "lname":"dave", "std":"1", "marks":"12000", "image":"image31.jpg", "id1":"1", "in_date":"0000-00-00", "upd_date":"2013-07-10" }, { "id":"34", "fname":"darshan", "mname":"d", "lname":"dave", "std":"1", "marks":"12000", "image":"image34.jpg", "id1":"1", "in_date":"2013-07-06", "upd_date":"2013-07-09" } ]
when alert json
in success
function shows me this:
[ { "id":"31", "fname":"darshan", "mname":"d", "lname":"dave", "std":"1", "marks":"12000", "image":"image31.jpg", "id1":"1", "in_date":"0000-00-00", "upd_date":"2013-07-10" },
what mistake?
you aren't parsing json. add datatype : 'json'
ajax call. tell jquery automatically parse json you.
$.ajax({ type: "post", url: "<?php echo base_url('welcome/liststd');?>", data: 'postdata=' + i, datatype: 'json', // <----- tell jquery parse json success: function (json) { var abc = json; document.getelementbyid("fname").innerhtml = abc[0].fname; } });
Comments
Post a Comment