CakePHP, JQuery .load a controller function

I'm having a little trouble getting Jquery to play nice with cakephp and I'm not really sure what the problem is.

view file, View/Members/index.ctp

<script>
  $(document).ready(function(){

    $("#place").click(function(event){
      $("#place").load('/member/jax', function(){
        alert("load successful");
      });
    });

  });

</script>
<div id="place"></div>

Controller file Controller/MembersController

public function jax() {
  echo "<p>TESTTHIS</p>";
  $this->layout='ajax';
  $this->render('/Elements/test');
}

and for completeness

Test element /View/Elements/test.ctp

<b>test element</b>

When I click on the div I get the "load successful" popup, but I do not get the "

TESTTHIS

that I expect the controller to print out, nor do I get the "test element" from the render.

Can anyone tell me where I'm going wrong? Thanks.

Answers


you can try with following:

$("#place").load('/members/jax',...

Conventionally controller in CakePHP call with plural name. So, I think it should members not member.


If you want to load the complete controller with view then print the URL of your controller and view in .load() through PHP


Need Your Help

Can't figure out how to reassign an element in a list of lists in this Python code

python nested-lists

I understand that how accessing elements in a list of lists usually works. I know that if you have a list L = [['a', 'b'], ['c', d'],['e', 'f']], you can access 'a' using L[0][0]. Still, I'm not su...

Use values instead of -1...1 for OpenGL drawing shapes?

c opengl glut

If I wanted to draw a plane in OpenGL, I would do something like the below: