Anuj TBE Anuj TBE - 3 months ago 11
jQuery Question

print json object in ajax response

I am using ajax to submit form and print response code.

This is php response array

$response['code'] = 401;
$response['message'] = 'Thank You';
$response['class'] = 'alert-success';
echo json_encode($response);


and this is ajax code

$.ajax({
dataType: 'json',
type: 'POST',
url: '/sellers/php-page',
data: dataString,
cache: false,
success: function(d) {
console.log(d);
}
});


output of
console.log(d)
gives

Object { code: 401, message: "Thank You", class: "alert-success" }


Now I have to print only message. How could I print/use single object out of array object ?

Answer
  success: function(d) {
     console.log(d.message);   // "Thank You"
  }