What I am actually trying to achieve, I am doing query in codeigniter. Data is coming properly but, I am quite unable to show it to HTML element. Please check json output in firebug console and code as below-
JSON Output:
{"founduser":
{
"user_id":"2",
"name":"Altab Hossen",
"email":"[email protected]",
"password":"",
"employee_id":"0122",
"nric_number":"K90031G",
"is_user_active":"1"}
}
Ajax Code
var userid = $("#userid").val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: base_url+"checkuser/"+userid,
data: "{}",
dataType: "json",
success: function (data) {
alert(data);
},
error: function (result) {
alert("Error");
}
});
Now: alert(data); returning me Object Object.
I want to do show only name (Altab Hossen) in div element: $('.showusername').html(data.name);
How Can I achieve?
Try,
$('.showusername').html(data.founduser.name);
and if you want to display a json as a string while debugging, you need to use JSON.stringify() like,
alert(JSON.stringify(data));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With