嘿,我發送了一個JSON編碼數組到我的JS頁面有兩個鏈接。Javascript和PHP數組值
{"download":"http://JapSeyz.dk/Test/Medarbejder/fileDownload.php?filename=test___1847598251_26-04-2013.png","view":"http://JapSeyz.dk/Test/Medarbejder/uploads/test___1847598251_26-04-2013.png"}
即輸出
它在陣列稱爲狀態,如果我嘗試狀態[點擊下載]它是不確定的,和狀態[0,1,2]等,只是給了我單個字符....如何從一次下載中選擇整個鏈接?
謝謝:)
繼承人所有的代碼..對不起(丹麥的一些文字,但我只是想顯示力量DL鏈接和視圖鏈接)
var links = JSON.parse(status);
var download = status.download;
var view = status.view;
var status = "Brug dette link hvis folk kun skal se dette <br /><div class='link-copy'>http://JapSeyz.dk/Test/Medarbejder/"+view+"</div><br /><br />Hvis du vil have folk til at downloade den skal du bruge dette link <br /> <div class='link-copy'>"+download;
//set the status message to that returned by the server
document.getElementById('status').innerHTML=status;
而且PHP:
$test = json_encode(array("download" => $link, "view" => "http://JapSeyz.dk/Test/Medarbejder/".$move));
echo returnStatus($ test);
你的代碼在哪裏? – Prisoner 2013-04-26 10:58:45
使用'obj = JSON.parse(status);'解析它。 – Rikesh 2013-04-26 10:58:49
檢查[json_decode](http://php.net/manual/en/function.json-decode.php)和[json_encode](http://php.net/manual/en/function.json-encode.php )PHP函數將json轉換爲php數組/對象,並將php轉換爲json .. – Svetoslav 2013-04-26 10:58:57