我如何獲得「LSZ09」。如何訪問JavaScript中的JSON數組
var el1=data[0];
alert(el1);
這使我的 「a」 從陣列,如圖1位給我R,2 R,3,4Y,..
陣列被通過接收到「回波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腳本接收,與去年線是:回聲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);
數組的整個轉儲實際上並不是你的代碼的一部分嗎? – Jonathon
此外,顯示您的PHP和JavaScript獨立 – Jonathon
@Jonathon亨德森不,它是從一個PHP腳本收到 – Faarbhurtz