Block ajax actions only work from the homepage. Help!
Permalink
I'm pretty new to Concrete5 and developed a block that has a few actions that I call via ajax.
Example:
I can now use the path http://mysite.com/getmapperquestions...
The route appears to be automatically setup when the block has been added to the home page and works as expected.
If I then put the block into another page on the site and keep it in the home page it still works fine, however if I remove it from the home page, the route no longer resolves.
Am I missing something obvious? Thanks.
Example:
I can now use the path http://mysite.com/getmapperquestions...
The route appears to be automatically setup when the block has been added to the home page and works as expected.
If I then put the block into another page on the site and keep it in the home page it still works fine, however if I remove it from the home page, the route no longer resolves.
Am I missing something obvious? Thanks.
Hi Willem.
Thanks for taking the time to respond.
I have looked at these posts and perhaps making a package is the way to go. I could then at least register some global routes. To be clear, I am calling the action from a js file that is loaded by my block controller so I have no way to use php to call $view-> or $this->.
I would really like to know how the action route is automagically registered globally when the block is on the home page but the route disappears if I remove the block. Is this a bug perhaps?
Example js:
Thanks for taking the time to respond.
I have looked at these posts and perhaps making a package is the way to go. I could then at least register some global routes. To be clear, I am calling the action from a js file that is loaded by my block controller so I have no way to use php to call $view-> or $this->.
I would really like to know how the action route is automagically registered globally when the block is on the home page but the route disappears if I remove the block. Is this a bug perhaps?
Example js:
// pathToEndPoint is my action - mysite.com/getmapperquestions p.loadJsonQuestions = function(pathToEndpoint) { $.ajax({url: pathToEndpoint, type:'POST', dataType: 'json'} ) .done(function (data) { self.parseJsonQuestions(data); }) .fail(function (jqXHR, textStatus, errorThrown) { self.dispatchEvent("questionsLoadFailed"); }) .always(function() { console.log("always"); }); };
your block does have a view.php file...you can add a bit of javascript there:
pathToEndPoint = <?php echo $this.....?>;
It will be available in your js file.
pathToEndPoint = <?php echo $this.....?>;
It will be available in your js file.
Hi again.
The block view loads a html5 canvas app that relies on other js files and I didn't want to have modify it to accept a path from the view.
I have found a solution which I will build upon later when I create a package.
For now, if anyone needs to create routes that map to their controller actions this is what I did:
1. Create the actions in your block controller
2. Open the file /application/bootstrap/app.php - In this file you can register custom routes to controllers or actions
3. Register the route. In my case this was
As long as the block is installed, this will now work anywhere within your site. I have added the block to a few pages everything appears to work as expected.
Thanks
The block view loads a html5 canvas app that relies on other js files and I didn't want to have modify it to accept a path from the view.
I have found a solution which I will build upon later when I create a package.
For now, if anyone needs to create routes that map to their controller actions this is what I did:
1. Create the actions in your block controller
2. Open the file /application/bootstrap/app.php - In this file you can register custom routes to controllers or actions
3. Register the route. In my case this was
/** * Custom route for getting career mapper questions **/ Route::register( '/getmapperquestions', 'Application\Block\CareerMapper\Controller::action_getmapperquestions' );
As long as the block is installed, this will now work anywhere within your site. I have added the block to a few pages everything appears to work as expected.
Thanks
https://www.concrete5.org/index.php?cID=780192...
https://www.concrete5.org/community/forums/5-7-discussion/view-actio...