Um zu sehen, was Ihr Json macht, machen Sie var_dump oder var_export.
Wie lässt vermuten, Ihre Antwort in der Variablen gespeichert wird $response
$object = json_decode($response);
var_export($object);
var_dump($object);
erhalten wir folgendes:
stdClass::__set_state(array(
'status' => 'success',
'message' =>
array (
0 =>
stdClass::__set_state(array(
'entry_id' => '1',
'entry_name' => '12345678',
'entry_body' => 'this is just the beginning update',
'entry_date' => '2016-05-01 08:25:51',
'status' => 'active',
'created_timestamp' => '2016-05-01 21:25:51',
'updated_timestamp' => NULL,
)),
1 =>
stdClass::__set_state(array(
'entry_id' => '2',
'entry_name' => 'one one one',
'entry_body' => 'this is just the beginning update 1',
'entry_date' => '2016-05-02 01:44:03',
'status' => 'active',
'created_timestamp' => '2016-05-02 14:44:03',
'updated_timestamp' => NULL,
)),
2 =>
stdClass::__set_state(array(
'entry_id' => '3',
'entry_name' => 'two two two',
'entry_body' => 'this is just the beginning update 2',
'entry_date' => '2016-05-02 01:44:13',
'status' => 'active',
'created_timestamp' => '2016-05-02 14:44:13',
'updated_timestamp' => NULL,
)),
),
))
object(stdClass)#511 (2) {
["status"]=>
string(7) "success"
["message"]=>
array(3) {
[0]=>
object(stdClass)#512 (7) {
["entry_id"]=>
string(1) "1"
["entry_name"]=>
string(8) "12345678"
["entry_body"]=>
string(33) "this is just the beginning update"
["entry_date"]=>
string(19) "2016-05-01 08:25:51"
["status"]=>
string(6) "active"
["created_timestamp"]=>
string(19) "2016-05-01 21:25:51"
["updated_timestamp"]=>
NULL
}
[1]=>
object(stdClass)#513 (7) {
["entry_id"]=>
string(1) "2"
["entry_name"]=>
string(11) "one one one"
["entry_body"]=>
string(35) "this is just the beginning update 1"
["entry_date"]=>
string(19) "2016-05-02 01:44:03"
["status"]=>
string(6) "active"
["created_timestamp"]=>
string(19) "2016-05-02 14:44:03"
["updated_timestamp"]=>
NULL
}
[2]=>
object(stdClass)#514 (7) {
["entry_id"]=>
string(1) "3"
["entry_name"]=>
string(11) "two two two"
["entry_body"]=>
string(35) "this is just the beginning update 2"
["entry_date"]=>
string(19) "2016-05-02 01:44:13"
["status"]=>
string(6) "active"
["created_timestamp"]=>
string(19) "2016-05-02 14:44:13"
["updated_timestamp"]=>
NULL
}
}
}
Wie Sie sehen können, Ihre Struktur löst zu einem Objekt, das ist ein assoziatives Array das ein Array enthält, das ein Objekt enthält, das ein assocaitve-Array ist;
Dies bedeutet, dass Sie nicht als assoziatives Array zugreifen können.
so das Objekt $ [ 'message'] wird nicht funktionieren, aber $ object-> Nachricht arbeiten :-)
var_dump($var->message[0])
zu
object(stdClass)#512 (7) {
["entry_id"]=>
string(1) "1"
["entry_name"]=>
string(8) "12345678"
["entry_body"]=>
string(33) "this is just the beginning update"
["entry_date"]=>
string(19) "2016-05-01 08:25:51"
["status"]=>
string(6) "active"
["created_timestamp"]=>
string(19) "2016-05-01 21:25:51"
["updated_timestamp"]=>
NULL
}
löst man es wie folgt zugreifen können: -)
$myobj = $var->message[0]
echo $myobj->status == 'active'
in Javascript es sein würde,
var obj = JSON.parse(message);
myobj = obj.message[0];
echo myobj.status == 'active';
Wenn Sie überschreiben jQuerys ajax Sie anrufen können sehen, dass der folgende Aufruf an den Server gesendet wird (den Code von meinem Snippet für sehen, wie diese sehen)
Wie Sie Ihre Argumente geschickt bekommen sehen, wie zusätzliche Argumente für den Server.
[Object] 0: Object Cache: false Daten: Object DATASRC: "message" Datentyp: "json" Fehler: (b, c) success: (b) Typ: „GET " url: "/ BlogApiV1/BlogApi/blogs"
und Ihre ajax-Antwort sollte wie folgt aussehen:
{
"status":"success",
"data": [
[
"1",
"12345678",
"this is just the beginning update",
"2016-05-01 08:25:51",
"active",
"2016-05-01 21:25:51",
null
],
[
"2",
"one one one",
"this is just the beginning update 1",
"2016-05-02 01:44:03",
"active",
"2016-05-02 14:44:03",
null
],
[
"3",
"two two two",
"this is just the beginning update 2",
"2016-05-02 01:44:13",
"active",
"2016-05-02 14:44:13",
null
]
]
}
entnehmen Sie bitte den Datentabellen Beispiele Seiten und schau dir die Source-Tabs unten an :-) sie geben Beispiele, wie sie erwarten, dass sie formatiert werden :-)
@ user3264461 was Sie sagen, ist richtig. Haben Sie in den Chrome-Entwicklungstools auf der Registerkarte "Netzwerk" nachgesehen, um sicherzustellen, dass das JSON-Element tatsächlich auf dem Frontend angezeigt wird und auf der Seite keine anderen js-Fehler vorliegen? –
@lolka_bolka "Nachricht" als String ist das richtige Argument für die Option "dataSrc" – edhurtig
@edhurtig mein Kommentar gelöscht, habe ich nicht erkannt, das ist ein DataTable Callback. – vaso123