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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

AJAX URL Problem


Go to End


4 Posts   1591 Views

Avatar
Garrett

Community Member, 245 Posts

19 July 2008 at 6:29am

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

Community Member, 69 Posts

19 July 2008 at 2:52pm

Edited: 21/07/2008 7:17pm

@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

Community Member, 245 Posts

22 July 2008 at 5:10am

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

Community Member, 69 Posts

22 July 2008 at 9:16am

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