0

I am getting following response from jquery ajax in json (in response array)

{
    "status": true,
    "message": "Data fetched successfully",
    "data": [{
        "id": "19",
        "employer_id": "5bea870168ebeb6db4d612c3",
        "employee_id": "5bea868b68ebeb6db4d612c1"
    }],
    "count": 1
}

How can i get "count" object in javascript/jquery from this json (not in php) ?

i tried with following code but not working for me

alert(response.count);

Barmar
  • 741,623
  • 53
  • 500
  • 612
amit
  • 1
  • 1
  • 18
  • 28

1 Answers1

0

You should console.log(data) in success function, with your object response.count still worked.

If response is array you can use console.log(response[0].count);

let response = {
    "status": true,
    "message": "Data fetched successfully",
    "data": [{
        "id": "19",
        "employer_id": "5bea870168ebeb6db4d612c3",
        "employee_id": "5bea868b68ebeb6db4d612c1"
    }],
    "count": 1
};
console.log(response.count);

response = [{
    "status": true,
    "message": "Data fetched successfully",
    "data": [{
        "id": "19",
        "employer_id": "5bea870168ebeb6db4d612c3",
        "employee_id": "5bea868b68ebeb6db4d612c1"
    }],
    "count": 1
}];

console.log(response[0].count);
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62