json_encode with page_list
Permalink
I have an ajax call that need to receive an array of pages.
What I have until now:
On Submit in PHP
in JS
But I receive undefined.
I guess it is because $results it is an object but not an array.
Any suggestions on how to receive pages and get pagename,url.
What I have until now:
On Submit in PHP
$path = ($_POST['path']); $page = Page::getByPath($path); $id = $page->getCollectionID(); Loader::model('page_list'); $pl = new PageList(); $pl->filterByParentID($id); $results = $pl->getPage(); echo json_encode($results);
in JS
success : function(data) { alert(data.cID); }
But I receive undefined.
I guess it is because $results it is an object but not an array.
Any suggestions on how to receive pages and get pagename,url.
Thank you for answer My response
From your code, but still I receive undefined.
Do I need to loop in JS??
[{"cID":"134","name":"About us"},{"cID":"135","name":"Certificates"},{"cID":"136","name":"FAQ"}]
From your code, but still I receive undefined.
Do I need to loop in JS??
Unless you're happy with just one page you need to loop through the result
There are existing addons for ajaxed page lists and my own Blocks By Ajax addon can be used with page list templates.
and then return $ret...