discuss.answer
-
☆ A M B ☆
- 24,524 Posts
Part II is for creating a CMP. If you want to access the data in the front-end with AJAX, you already have all that you need.
In MODX, AJAX is generally done with a resource with no template and nothing but the snippet that fetches the data. The resource's URL is the URL for the AJAX query. The snippet fetches the data, then processes it to return whatever you want for the AJAX output. You can fetch data and convert it to a JSON array to return, or you can have MODX generate formatted HTML output with getChunk, and return fully formatted HTML to load into a specified DOM container.
The trick is to keep the two things separate: the AJAX request to the URL and the processing of the returned content is the job of Javascript. Receiving the request and doing whatever is need to generate the content to return is the job of your snippet. You just need to know what parameters to send to the snippet, and what format you need to get back.