Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » AJAX URL Problem

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1173 Views
  • Garrett
    Avatar
    Community Member
    245 Posts

    AJAX URL Problem Link to this post

    Hi,

    I am having a lot of problems using Ajax to load content from other URL's in the sense that the URL in the address bar never changes, which of course causes strange behavior when refreshing the browser, going back and forward, goingdirectly TO a page, etc.

    I am hoping that someone can explain to me what this whole concept of "www.mysite.com/mypage/myaction/" as opposed to just "www.mysite.com/mypage/" is? In the SS AJAX tutorial [ http://doc.silverstripe.com/doku.php?id=recipes:ajax_basics ]? I have a feeling this is related, is it not?

    First of all, $('element_name').load(url) successfully loads my content fine completely WITHOUT any of the isAjax() code given in the tutorial, so I am not sure what this code is for.

    Secondly, the tutorial says, "Above is an example of an action that can be called from your page. In the html it is shown how to call this action." However, there is no explanation of WHAT this action IS, and how to assign/define it.

    I'm assuming that the whole idea with the "second part" to the URL ("www.mysite.com/mypage/myaction/") is to TELL Silverstripe that we are using Ajax, right? So how do I get the URL of page content I am loading into my current URL to "stack on" to my current URL as indicated by the /$page/$action concept? Does /$action MEAN the second part? The URL of the Ajax-called page?

    I'm doing an image gallery. The URL is:

    .../portfolio-web-interactive/

    Then I click on a picture, using $('element_name').load('portfolio-wi-project-1');

    How can I get the URL then to become:

    .../portfolio-web-interactive/portfolio-wi-project-1

    ?

    Isn't this the way it's supposed to work? Do I use urlParams to set this action or what?

    Any help would be GREATLY and TRULY apperciated-- my whole site depends on this URL thing getting cleared up.

    Thanks in advance,
    Garrett

  • Phalkunz
    Avatar
    69 Posts

    Re: AJAX URL Problem Link to this post

    @Garret: I haven't done much of ajax yet but I can answer your first question and it might also explain the rest of the issue. The second part of the url is the name of the controller (mypage is mapped to MyPage_Controller and the third part of the url is the action name which is the function of the controller. If there's no action name specified in url at all then index function of the controller will be called. If we put these in php, it looks like this:

    <?php
    ...
    class MyPage_Controller extends Page_Controller {
    // Gets called when there is no action specified
    function index() {
    ...
    }
    // Gets called when this url www.mysite.com/mypage/myaction/ is invoked
    function myaction() {
    ...
    }
    }
    ...
    ?>

    Hope this helps

  • Garrett
    Avatar
    Community Member
    245 Posts

    Re: AJAX URL Problem Link to this post

    Yes, but www.mysite.com/mypage/myaction/ implies a URL. HOW does www.mysite.com/mypage/myaction/ get "invoked"?? Do I have to put this in my Meta-Data tab AS the url???

    Thanks,
    Garrett

  • Phalkunz
    Avatar
    69 Posts

    Re: AJAX URL Problem Link to this post

    You don't have to anything extra really. There's a rule that maps the url to the page/page_controller and the action (function) in the php code. You should have a look at MVC model

    1173 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.