0

How can I use Jquery to only extract 'customers_firstname' from the json format?

<?php echo json_encode($users) ?>

Output

[{"Customer":{"id":"13","customers_gender":"M","resumetest":"a15ff2aa27d616636b5bc30fac4dba38733f4e5f","created":"2013-01-29 13:49:06","modified":"2013-03-14 11:50:18","customers_firstname":"Gerald","customers_lastname":"Russ"}},{"Customer":{"id":"14","customers_gender":"F","resumetest":null,"created":"2013-01-29 15:41:23","modified":"2013-02-14 15:08:42","customers_firstname":"Jim","customers_lastname":"Carrie"}}] 
DANLEE
  • 443
  • 1
  • 8
  • 25

2 Answers2

1

Try this :

DEMO

HTML

<ul id="nameList">
</ul>

JS

var customers = [{"Customer":{"id":"13","customers_gender":"M","resumetest":"a15ff2aa27d616636b5bc30fac4dba38733f4e5f","created":"2013-01-29 13:49:06","modified":"2013-03-14 11:50:18","customers_firstname":"Gerald","customers_lastname":"Russ"}},{"Customer":{"id":"14","customers_gender":"F","resumetest":null,"created":"2013-01-29 15:41:23","modified":"2013-02-14 15:08:42","customers_firstname":"Jim","customers_lastname":"Carrie"}}];

$.each(customers, function (index, item) {

        $("#nameList").append("<li>" + item.Customer.customers_firstname + "</li>");
    });
Mate
  • 4,976
  • 2
  • 32
  • 38
  • thanks mate! can i ask? what does console.log() does? how can i append the result in a table tag that loop and display on the results. – DANLEE Mar 21 '13 at 03:25
  • For console.log() check this http://stackoverflow.com/questions/4743730/what-is-console-log-and-how-do-i-use-it . Updated :) – Mate Mar 21 '13 at 03:36
0

You can use below code in your AJAX success block

$.each(json_data, function (index, customer){//here json_data is success response from the Server
if (customer){
console.log(customer["customers_firstname"];
}
})
Raghuveer
  • 2,630
  • 3
  • 29
  • 59