Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

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

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

AJAX URL Problem


Reply

4 Posts   1192 Views

Avatar
Garrett

19 July 2008 at 6:29am Community Member, 245 Posts

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

Avatar
Phalkunz

19 July 2008 at 2:52pm (Last edited: 21 July 2008 7:17pm), 69 Posts

@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 :)

Avatar
Garrett

22 July 2008 at 5:10am Community Member, 245 Posts

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

Avatar
Phalkunz

22 July 2008 at 9:16am 69 Posts

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 :)