You *can* use external connectors (as explained in the
Custom Manager Pages docs), although one problem with that method is that you need to implement your own security/permission checking.
A "better" (well, I don’t know if it’s better, but it sure is easier!) way to do this is by using a resource just for AJAX requests for your component. To do this:
1. Create a new Content Type (System | Content Types).
Name: JSON
MIME Type : application/javascript
File Extension: .js
Binary: Leave as default (No)
2. Create a new Resource and assign the new JSON Content Type. You can leave the template as empty.
3. Place your (AJAX) snippet call as the content. You could either use a separate AJAX-only snippet (as opposed to a regular snippet), or use a snippet parameter like &ajax=`1`, to let your snippet know whether to output a parsed chunk/content, or a JSON object.
4. Your non-AJAX snippet should output the actual JS code. With jQuery, something like this is enough to perform a basic AJAX request:
$.ajax( {
url : "index.php?id=MY_AJAX_PAGE_ID",
data : {
param1 : "some-value",
param2 : "another-value"
},
success : function( data, status, xhr ) {
// do something with data
},
dataType : "json"
} );
Your AJAX snippet should "echo" the content of the request to the browser, and your JS should be responsible for taking the request data and displaying it.
Hopefully this helps!