5.7 Single page ajax MVC
PermalinkInterestingly I tried to recreate the example above verbatim and this didn't work for me either. I think that it may be my route register.
The controller is in the directory application/controllers/single_page/job_search.php
The view file is in the directory application/single_pages/job_search/view.php
In the bootstrap app.php I am registering the route in the following manner
Route::register( '/job/{id}', 'Application\Controller\SinglePage\Job::getDetail' );
My controller is defined as
namespace Application\Controller\SinglePage; use Concrete\Core\Controller\Controller; use \Concrete\Core\Http\Request; use Core; class Job extends Controller { public function getDetail() { $jobID = Request::getInstance()->get('id'); $detail = 'Job Id "' . $jobID . '", '; echo $detail; } }
The ajax call in the view.php file:
<script type="text/javascript"> $(document).ready(function() { $('#myModal').on('show.bs.modal', function(e) { var id = $(e.relatedTarget).data('id'); $.ajax({ url: "<?php echo URL::to('/job');?>/" + id, success: function(response) { $('#ajax-content').html(response); } }); }); }); </script>
I haven't worked out a way to see if the call is getting to the getDetail function to help me debug the issue. Is there a way to do that or am I doing something wrong?
Using the debugging I have confirmed that I have a routing error as I am getting a 404 error as the ajax routine is calling the function with the following URLhttp://ruru/concrete5/index.php/job/getDetail/5435,... which is not finding the function on the controller file.
I have been struggling with this for a while now, without success and I am now wondering whether I should try the approach of using the url: '<? echo $this->action('getDetail'); ?>', rather than my echo URL::to framework. Your thoughts?
Glenn
Add
to your class. Then use it like this
You can then see the result in your logs, in your dashboard.
Also, you should use your ajax call differently so you can get back some information there as well
The comments in the code tell you how it can be useful