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.

 
inertia replied on at Permalink Reply
I'm kinda looking for the same thing.

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.
ryan replied on at Permalink Reply
ryan
You should be able to exit out of your controller function & no html will be displayed. Something like this:

$.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.
robertkoeberl replied on at Permalink Reply
hi @all!

is it possible to use "$this->action('action_update');" in a BlockController / in the funtion on_page_view()??
jordanlev replied on at Permalink Reply
jordanlev
If it's in the same controller file, perhaps you can just call the function directly -- $this->action_update()
robertkoeberl replied on at Permalink Reply
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?
jordanlev replied on at Permalink Reply
jordanlev
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?
robertkoeberl replied on at Permalink Reply
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>
jordanlev replied on at Permalink Reply
jordanlev
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:
<script>
var update_url = <?php echo $this->action('update'); ?>;
</script>


Then reference that variable from your Ajax code.

Hope that helps!
robertkoeberl replied on at Permalink Reply
ok - i think there is no other way... ;-)
but - i avoid variables in html...

thanks!