ajax request in custom block
Permalink
Hi, I'm making a custom block, which has "just in place editing" function, with jeditable(http://www.appelsiini.net/projects/jeditable)
I added update_action method in view.php
<code>
$('#editable').editable( '<?php echo $this->action('update'), {
</code>
and update_action in controller.php
<code>
function action_update() {
// save data to db.etc.
return true;
}
</code>
Problem is entire HTML page is returned in div#editable.
How can I render simple text line from action_update function?
thank you for your help.
I added update_action method in view.php
<code>
$('#editable').editable( '<?php echo $this->action('update'), {
</code>
and update_action in controller.php
<code>
function action_update() {
// save data to db.etc.
return true;
}
</code>
Problem is entire HTML page is returned in div#editable.
How can I render simple text line from action_update function?
thank you for your help.
You should be able to exit out of your controller function & no html will be displayed. Something like this:
If you don't exit it'll render the page.
/tools pages are also intended for this, but you'd have to manually check permissions.
$.post('<?=$this->action('action_update');?>'); public function action_update() { echo "hello"; exit; }
If you don't exit it'll render the page.
/tools pages are also intended for this, but you'd have to manually check permissions.
hi @all!
is it possible to use "$this->action('action_update');" in a BlockController / in the funtion on_page_view()??
is it possible to use "$this->action('action_update');" in a BlockController / in the funtion on_page_view()??
If it's in the same controller file, perhaps you can just call the function directly -- $this->action_update()
hi
no, what i mean is, i need the URL/REQUEST!
"$this->action('update');", called in view.php returns for example "/index.php?cID=57&bID=103&arHandle=Main&ccm_token=1280304245:d7d4db940f4693c8b27bebd042d38c62&btask=passthru&method=update" - and this is the string what i need - but in controller in the function "on_page_view()"
is this possible?
no, what i mean is, i need the URL/REQUEST!
"$this->action('update');", called in view.php returns for example "/index.php?cID=57&bID=103&arHandle=Main&ccm_token=1280304245:d7d4db940f4693c8b27bebd042d38c62&btask=passthru&method=update" - and this is the string what i need - but in controller in the function "on_page_view()"
is this possible?
I don't think this is possible. What are you trying to do exactly with this technique? Perhaps there is another way to achieve your goal?
ok...
i´m programming a ajax-vote. in the view.php i have my div´s width my stars...
in the controller, i place my javascriptcode (<script>) into the header - in the "function on_page_view()". now - i use jquery and set the onclick attribute to each star.
4 example: $(div-star).click(ajax...AND NOW I NEED THE URL FOR SEND A REQUEST...);
do you know what i mean?
i dont want do use <div onclick="JAVASCRIPT"></div>
i´m programming a ajax-vote. in the view.php i have my div´s width my stars...
in the controller, i place my javascriptcode (<script>) into the header - in the "function on_page_view()". now - i use jquery and set the onclick attribute to each star.
4 example: $(div-star).click(ajax...AND NOW I NEED THE URL FOR SEND A REQUEST...);
do you know what i mean?
i dont want do use <div onclick="JAVASCRIPT"></div>
I see. Unfortunately there is no perfectly clean way to do this. What I've done in similar situations is set a JavaScript variable in the view.php file, like this:
Then reference that variable from your Ajax code.
Hope that helps!
<script> var update_url = <?php echo $this->action('update'); ?>; </script>
Then reference that variable from your Ajax code.
Hope that helps!
ok - i think there is no other way... ;-)
but - i avoid variables in html...
thanks!
but - i avoid variables in html...
thanks!
I'm really new to C5, but what would be useful here is a method that can be called (from the controller?) to render the view without a template wrapped around it.