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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

How to use ajax, to load different pages in


Reply


2 Posts   1658 Views

Avatar
duskydesigns

Community Member, 15 Posts

16 June 2011 at 8:52am

Hi all,

I got a question about the workings of ajax calls within silverstripe. Im trying to load external pages into one page, but so far its failing. What i need to do is get the title, description and images. Im trying to do this through jQuery but i cant get it to work. I think ive forgot something or am just missing something huge. If anyone can help me out that would be appreciated. I tried ajax_recipes but i think its deprecated because i got a warning that a string did not exist.

this is what im trying to do:
http://net.tutsplus.com/tutorials/javascript-ajax/5-ways-to-make-ajax-calls-with-jquery/
   
$.ajaxSetup ({
      cache: false
   });

   var ajax_load = "<img src='themes/duskydesigns/images/load.gif' alt='loading...' />";
$(".portfolio-product").click(function(){
      var url = $(this).attr( 'rel' ) + 'ajax';
      $("#result").html(ajax_load).load(url);
      alert( url );
});

Im trying to get the url through the rel wich is just #relativelink of the page in question. Im familiar with javascript but not much with ajax calls and especially not in silverstripe, any help would be appreciated!

Avatar
moloko_man

Community Member, 72 Posts

17 June 2011 at 7:49am

afaik, ajax_recipes is out of date and deprecated.

I've done many ajax calls pulling in children pages into a "holder" page. and they work fine. I guess I'm "missing something huge" by not seeing all your code. What do you mean by external pages, are you pulling in random pages from your site, child pages, another site's pages?

while your jquery looks fine, I would recommend using .live instead of .click, for a lot of reasons that this forum isn't meant for.
$(".portfolio-product").live('click', function() {
your jquery load stuff here
}};

I would check to see if your function is even being called, by throwing in an alert(); then if so have it load to a static div tag on your page and see if its getting loaded.