I creating APP with SMS function and I want to display text messages and their details. I tried do something like this but this doesn't work. Here is format data from SMS API:
object(stdClass)#30 (1) {
["items"]=>
array(2) {
[0]=>
object(stdClass)#31 (7) {
["id"]=>
int(396629)
["type"]=>
string(2) "nd"
["phone"]=>
string(12) "123456789"
["recived"]=>
string(19) "2016-01-16 16:36:42"
["blacklist"]=>
bool(false)
["text"]=>
string(19) "Vrs wifi nie dziala"
["contact"]=>
object(stdClass)#32 (10) {
["id"]=>
string(9) "272075197"
["first_name"]=>
string(6) "FirstName"
["last_name"]=>
string(5) "LastName"
["company"]=>
string(0) ""
["phone"]=>
string(12) "123456789"
["email"]=>
string(0) ""
["tax_id"]=>
string(0) ""
["city"]=>
string(0) ""
["address"]=>
string(0) ""
["description"]=>
string(0) ""
}
}
[1]=>
object(stdClass)#33 (7) {
["id"]=>
int(396609)
["type"]=>
string(2) "nd"
["phone"]=>
string(12) "123456789"
["recived"]=>
string(19) "2016-01-16 14:36:53"
["blacklist"]=>
bool(false)
["text"]=>
string(3) "vrs"
["contact"]=>
object(stdClass)#34 (10) {
["id"]=>
string(9) "272075197"
["first_name"]=>
string(6) "FirstName"
["last_name"]=>
string(5) "LastName"
["company"]=>
string(0) ""
["phone"]=>
string(12) "123456789"
["email"]=>
string(0) ""
["tax_id"]=>
string(0) ""
["city"]=>
string(0) ""
["address"]=>
string(0) ""
["description"]=>
string(0) ""
}
}
}
}
I do somethink like this:
$result = $serwersms->messages->recived('eco|nd|ndi|pre');
$output = array();
foreach ( $result->items as $key ) {
$row = array();
$row[] = $key->id;
//var_dump RETURN: int(396609), etc.
$row[] = $key->phone;
$row[] = $key->text;
$output[] = $row;
}
$output = array( "data" => $output );
echo json_encode($output);
And AJAX:
$.ajax({
url : "MY_URL_TO_FUNCTION",
type: "GET",
dataType: "JSON",
success: function(data) {
console.log(data.id);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('Error');
}
});
But I don't getting data, only 'undefined' in console. AJAX response:
{"data":[[396629,"123456789","Vrs wifi nie dziala"],[396609,"123456789","vrs"]]}
What is wrong?