ajax from edit.php
Permalink
Hi all,
Is it possible to communicate in ajax mode to a controller of a package from his add.php or edit.php ?
In other words, it is possible to use the great feature "action" from the file add & edit? I know the general procedure (very well explained in the documentation) but I can not retrieve the url :
I try :
But nothing..
I suppose that i need to keep first the controller?
Is it possible to communicate in ajax mode to a controller of a package from his add.php or edit.php ?
In other words, it is possible to use the great feature "action" from the file add & edit? I know the general procedure (very well explained in the documentation) but I can not retrieve the url :
I try :
$v = View::getInstance(); $postUrl = $v->action('test');
But nothing..
I suppose that i need to keep first the controller?
Hi Jordanlev
Can please help me
http://www.concrete5.org/community/forums/block_requests/how-can-id...
Thanks
Can please help me
http://www.concrete5.org/community/forums/block_requests/how-can-id...
Thanks
can this be done with block tools as well as package tools? In my controller.php I have the following add function declared.
and in my auto.js I have
but when I test the code by supplying the variable called url as an argument to the JQuery alert method
it simply prints "Tool found at "<?php echo $my_tools_url; ?>""
I'm trying to pass the path to my tools directory as a variable to the auto.js file instead of hardcoding it.
public function add() { $th = Loader::helper('concrete/urls'); $this->set('my_tools_url', $th->getToolsURL('getinfo')); }
and in my auto.js I have
var url = '<?php echo $my_tools_url; ?>';
but when I test the code by supplying the variable called url as an argument to the JQuery alert method
alert('Tool found at: "'+url+'"');
it simply prints "Tool found at "<?php echo $my_tools_url; ?>""
I'm trying to pass the path to my tools directory as a variable to the auto.js file instead of hardcoding it.
If you have a play with my Ajax lessons howto and associated addon it shows all permutations of ajax mechanisms in add, edit and view.
I've had a look and can't seem to find where you're grabbing the tool path. Specifically in the Ajax call that is.
if i use
and then echo the value of $getinfo in add.php it gives me the path I'm looking for I just can't seem to get this variable into my auto.js file
if i use
public function add(){ $this->set_block_tool('getinfo'); } private function set_block_tool($tool_name){ $tool_helper = Loader::helper('concrete/urls'); $bt = BlockType::getByHandle($this->btHandle); $this->set ($tool_name, $tool_helper->getBlockTypeToolsURL($bt).'/'.$tool_name); }
and then echo the value of $getinfo in add.php it gives me the path I'm looking for I just can't seem to get this variable into my auto.js file
The set() is only visible in the add/edit form.
An easy way to pass it to auto.js is to attach it as a data attribute to a dom element (in the add/edit form), then in auto.js to read that data attribute.
An easy way to pass it to auto.js is to attach it as a data attribute to a dom element (in the add/edit form), then in auto.js to read that data attribute.
that feels a little like cheating lol but if it's the only way it can be done then it's the only way and I'll do it :)
Thanks John you're a legend
Thanks John you're a legend
Ho! Jordan thank you very much for these clear and precise explanation. I was already using a lot of ajax in my block but not as cleanly.
I'm going to see the gallery of which you speak.
I'm going to see the gallery of which you speak.
Now you add/edit.php file has that $my_ajax_url available to pass into javascript functions, for example:
If you want to have your javascript in your auto.js file (like you should -- keep it out of the add/edit.php which should mostly be just html), you need to declare a javascript variable in add/edit.php for that ajax url, then you can access that variable from the auto.js file.
Check out the code in "Simple Image Gallery" in the marketplace to see an example of how I've done this (I used it to dynamically populate the list of filesets that the user can choose from in the add/edit form).
-Jordan