Calling action in controller.php from blocks view.php

Permalink
Hi

I want something simple. I want to call a function in my controller.php from my view.php. I want to load it with jquery's "get" function.

I did the same already in single pages and there its working without a problem. But in a normal block it's not. The return is always the full page, it can't access the action in the controller.php.

Code in view.php, something like this:
$.get("<? echo $this->action('action_myaction'); ?>", function(data){
  //do something
});


Code in controller.php, something like this:
public function action_myaction(){ 
  echo "something";
  exit;
}


I tried already to rename the call or function without the "action_" in the name, but just nothing works. What am I doing wrong? I'm sure it's something very simple... and I'm just to blind!

 
Kiesel replied on at Permalink Best Answer Reply
Ah, I knew it's something tiny and stupid!

Found it (the first & is a &-a-m-p-; without the -, editor changes it always):

$.get("<?= str_replace("&","&",$this->action('myaction')) ?>", function(data){
  //do something
});


Did the trick, maybe it helps someone else. Case closed!