Ajax request from CKEditor
Permalink
Running 8.4.2, I am working on a CKEditor plugin for a website (not part of a package). When the new button is clicked, the selected text will be used to perform an AJAX request on the server. For example, an editor could type and select a username, the AJAX request would return information about that user, and then the CKEditor selected content would be replaced with an anchor tag, title attribute with full name, linking to the user's home page, etc. AJAX calls on blocks and single pages are pretty simple in Concrete5, but I'm having trouble determining/deciding where the server code should exist for this type of request.
I'm not sure if there is an "official" place to put the server code for a request of this nature (I couldn't find anything on Google, StackOverflow, forums, etc.), so this may be an opinion question.
The simplest thing I can think of, is to create a single page that has an empty view, and then process the AJAX requests in the controller, but that seems like overkill and a bad hack. I have all the other pieces working, so I'll go with the single page if I don't come up with a better idea, but Is there a better place to put the server code for the AJAX request?
I'm not sure if there is an "official" place to put the server code for a request of this nature (I couldn't find anything on Google, StackOverflow, forums, etc.), so this may be an opinion question.
The simplest thing I can think of, is to create a single page that has an empty view, and then process the AJAX requests in the controller, but that seems like overkill and a bad hack. I have all the other pieces working, so I'll go with the single page if I don't come up with a better idea, but Is there a better place to put the server code for the AJAX request?
You can declare a route that maps an ajax URL to any controller/method. It doesn't have to be a page controller. In a package, you would declare the route in the package controller on start.
Well that was simple, thanks!