Ich möchte eine JSON-Datei von einer PHP-Seite bekommen, aber mein Code funktioniert nicht, was ist los?Ajax get json Funktion funktioniert nicht
my php page is
header('Content-type: application/json');
$jsonstart="{'files' : [";
$jsonend="]}";
$content="{'firstname' : '".$_GET['name']."' , 'lastname' : 'izadi'}";
$jsonfile=$jsonstart.$content.$jsonend;
print $jsonfile;
my ajax code is
$(document).ready(function(){
$.getJSON("getfilesinfo.php?name=afshin", function(data){
alert();
var test=JSON.parse(data);
alert("Data: " + test.files[1].firstname + "\nStatus: " + status);
});
});
Sie müssen verwenden 'json_encode (ARRAY)' – Rayon
, was Sie, wenn Sie Daten Konsole bekommt also 'Konsole. log (data); 'im getJSON() Callback? –
'$ jsonfile' ist kein gültiges' JSON' – Rayon