We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Url for ajax using JQuery (solved)

Hi, I am new to Phalcon and php framework in general. I am having problem building url for calling controller/action through JQuery.

I have a PageController which looks like this:

class PageController extends Phalcon\Mvc\Controller{

  public function indexAction($id){
    if($id)
      echo $id;
  }

  public function showAction(){    
  }
}

With index.phtml

<?php
// index.phtml
echo $this->getContent();
?>
<a id="support" href="#">click here</a>
<div class="extend"></div>

and show.phtml

<?php
//show.phtml
echo $this->getContent();
?>
<p> this is show page </p>

and the jquery:
$(document).ready(function(){
  $('#support').click(function(e){
    e.preventDefault();
    $('.extend').load('https://localhost/page/show');
  });
});

Yes, it's a simple script. The javascript and JQuery are in different files My current position is in 'https://localhost/page/index' I am trying to load up 'page/show' inside the 'extend' class div in index.phtml file.

The problem I am having is the url inside JQuery.load function. Here's what I've tried so far: $('.extend').load('https://localhost/page/show'); $('.extend').load('<?php echo $this->url->get('page/show'); >?'); $('.extend').load('page/show'); And none of them works. The number 3 works but it's more like the 'page/show' just becomes parameter for indexAction.

Am I missing something here. thanks



2.0k
Accepted
answer

Sorry about that seems I got it resolved. forgot to put a comment on the code '$this->view->disabled();

Also, just a heads up that you can use this syntax highlighting as explained here: https://forum.phalcon.io/discussion/1/welcome-to-the-forum