我如何获得“LSZ09”。
var el1=data[0];
alert(el1);
这给了我数组中的“a”,因为位置 1 给了我 r, 2 r, 3 a, 4y ,..
该数组通过“ echo json_encode($punten); ”接收
另外当我尝试
var jsonDataArray = JSON.parse(data);
我收到语法错误:
SyntaxError: JSON.parse: unexpected character
代码:
$.ajax({ url: 'getPunten.php',
data: {statnam: jSelectedStation[0]},
type: 'get',
success: function(data) {
从 php 脚本接收,最后一行是:echo json_encode($punten);
[{"STATDEV":"LSZ09 ","0":"LSZ09 ","DEVPKT":"1","1":"1","PKTTYP":"S","2":"S","KARTNR":"0","3":"0","BITNRK":"1","4":"1","BITSTATUS":"0","5":"0","TYPE":"I ","6":"I "},{"STATDEV":"LSZ10 ","0":"LSZ10 ","DEVPKT":"1","1":"1","PKTTYP":"S","2":"S","KARTNR":"0","3":"0","BITNRK":"2","4":"2","BITSTATUS":"0","5":"0","TYPE":"I ","6":"I "}
php:
$db = new PDO ("xxxx");
$qry="SELECT r.refnam, r.zustnr FROM refdev r INNER JOIN (SELECT refnam, COUNT(*) cnt FROM refdev rc GROUP BY refnam) rc ON rc.refnam = r.refnam LEFT OUTER JOIN texte t ON r.sigtnr = t.textnr WHERE rc.cnt = $aantal AND t.tstring LIKE '%$tekst%' ORDER BY r.refnam, r.zustnr";
$filterQry = $db->query($qry);
$filtered = $filterQry->fetchAll();
echo json_encode($filtered);