Dynamic block loading

Permalink
I'm using such a script to load some content onto my page:

<script>
$(document).ready(function() {
$(".testButton").click(function(){
$('#loadIntoThisDiv).load('urlWhereTheInformationToBeLoadedResides #specificDivIdToExtractFrom');
});
});
</script>

..This is sorted out and works fine. However, I'd like that page which is being pulled in to have some buttons on the side and also pull in data dynamically. This works on the page itself but fails to work when already being pulled in. Does this make any sense at all? ...it's as if I'm missing something with this secondary set of scripts...

One of my first posts so describing the technical issues is a little difficult right now.

binomonkey
 
chemmett replied on at Permalink Reply
chemmett
This is more of a general javascript question rather than concrete5 specific, but I'll take a stab at it.

When the secondary content gets loaded, the document.ready event has already fired, so if you have code like this within that content it's not going to be executed.

The best way to do this is to add the code you want to execute as the last parameter of the "load" function. Seehttp://stackoverflow.com/questions/8939127/jquery-executing-javascr...

However if your dynamic content can change or is fairly complicated, this may not be feasible. You could try just adding the code you want to run to a script tag at the end of the content and NOT wrapping it in the document.ready event, so it executes as soon as the content is inserted into the page. Just make sure the script tag is at the very end of your dynamic content, otherwise it will execute before the HTML part of the content has been inserted into the page.
binomonkey replied on at Permalink Reply
binomonkey
Thanks for the reply. I'll look into it.
cheers,



On Monday, May 19, 2014 2:16 PM, concrete5 Community <discussions@concretecms.com> wrote:
binomonkey replied on at Permalink Reply
binomonkey
Got the first issue resolved by tweaking some code. Now I'm having trouble displaying code controlled by javascript like slideshow to come in dynamically. On the page being loaded, blocks such as content and image come in fine. Those like slideshow however dont display. The div area shows but the data does not. Probably a double javascript load issue?
Thanks
binomonkey replied on at Permalink Reply
binomonkey
So I just realized after some testing that the issue I resolved before was really just a workaround fix. What I did was load the javascript on click functions on the page being viewed. The basic issue I need to fix and understand and the one I need help with is...
How do I dynamically load javascripted blocks?
Believe you me, I'm actually trying to explain this as best as possible.
Cheers and thanks,
Bjorn
mnakalay replied on at Permalink Reply
mnakalay
Hello,
There's an add-on in the marketplace called Rapid Ajax Paging that would allow you to load a page in a container using ajax (which is what it seems you're trying to do)
You can find it herehttp://www.concrete5.org/marketplace/addons/rapid-ajax-paging/...

I worked with it and it's pretty good. Also if you're goal is to learn rather to quickly reach the goal, I still suggest you buy it and have a look at the code as well as code from another add-on called Blocks by Ajax (http://www.concrete5.org/marketplace/addons/blocks-by-ajax/) that loads only blocks not whole pages.
binomonkey replied on at Permalink Reply
binomonkey
Thank you, I will look into those addons. I do feel like I'm on the cusp of solving this "last" issue..famous words that I"m pressed to find answers myself. Maybe the investment into buying and learning from the tools you mentioned will speed the learning process.
Thanks for information,
Bjorn