Ajax call in package is not working
Permalink
Hello everybody!
I'm trying to do an ajax call. But the result is, that the class I've defined is not found. The full call was not successfull.
This is based on the tutorial you will find athttp://c5hub.com/learning/ajax-57-style/...
I've changed it to work from a package
It should be included in a single page.
My structure:
packages/nak_newsletter/ajax/ajax.php
view.php
packages/nak_newsletter/controller.php
The return message is: "\Concrete\\Package\\NakNewsletter\\Ajax\\Ajax\" does not exist."
Can anybody help me?
Thanks!
Chris
I'm trying to do an ajax call. But the result is, that the class I've defined is not found. The full call was not successfull.
This is based on the tutorial you will find athttp://c5hub.com/learning/ajax-57-style/...
I've changed it to work from a package
It should be included in a single page.
My structure:
packages/nak_newsletter/ajax/ajax.php
namespace Concrete\Package\NakNewsletter\Ajax; class Ajax extends Controller { public function processForm() { $animal = Request::getInstance()->get('favorite'); $th = Core::make('helper/text'); $animal = $th->sanitize($animal); echo 'You told us your favorite animal is a "' . $animal . '", so we updated this page with that information using AJAX. Boom!'; } }
view.php
<?php defined('C5_EXECUTE') or die('Access Denied.'); $form = Loader::helper('form'); $opts = array('dog' => 'Dog', 'cat' => 'Cat'); echo $form->label('animal', 'Which animal is best?'); echo $form->select('animal', $opts, 'dog'); ?><div id="ajax-content">Return</div> <script type="text/javascript"> $(document).ready(function () { $('#animal').on('change', function (e) { alert("Aua"); var animal = $(this).val(); alert ("Animal ist: " + animal); $.ajax({ url: "<?php echo URL::to('nak_newsletter/process_form'); ?>/" + escape(animal),
Viewing 15 lines of 23 lines. View entire code block.
packages/nak_newsletter/controller.php
namespace Concrete\Package\NakNewsletter; use Package; use Database; use BlockType; use Concrete\Core\Backup\ContentImporter; use AssetList; use Asset; use Route; defined('C5_EXECUTE') or die('Access Denied.'); class Controller extends Package { protected $pkgHandle = 'nak_newsletter'; protected $appVersionRequired = '5.7.1'; protected $pkgVersion = '0.0.2'; ... public function on_start() {
Viewing 15 lines of 19 lines. View entire code block.
The return message is: "\Concrete\\Package\\NakNewsletter\\Ajax\\Ajax\" does not exist."
Can anybody help me?
Thanks!
Chris
Thanks in advance!