S
S
Sergey2017-02-21 00:04:52
JavaScript
Sergey, 2017-02-21 00:04:52

How to loop through an array in jquery?

Good afternoon, I can not figure out how to split the array correctly.
I am making a request via Ajax. On the server there is a selection in basis.

while ($res = mysql_fetch_array($query)){
  echo json_encode([
     'family'=>$res['family'],
      'name'=>$res['name']	
            ]);
}

I receive data like this.
var obj = JSON.stringify(data)
data = JSON.parse(obj);


The data in data .
{"family":"Петров","value":"Иван"}
{"family":"Иванов","value":"Петр"}
{"family":"Сидоров","value":"Вадим"}


I can't figure out how to loop through them.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-02-21
@interests70

$res = array();
while ($res = mysql_fetch_array($query))
    $res[] = array('family'=>$res['family'], 'name'=>$res['name']);
echo json_encode($res);

Then an array will be returned to JS, which can be iterated through each.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question