Embedding forum using AJAX

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Embedding forum using AJAX

Democracy Monkey
Hello,

I want to embed the forum using an AJAX call. However when I do this, only the link is displayed (from the code snippet to generated by nabble) and the javascript is not executed to properly embed the forum. I know this is normal security behaviour, however I cannot figure out the workaround for the sites displayed in the examples on nabble http://n2.nabble.com/help/Answer.jtp?id=36 . They almost all use AJAX calls to display their forums. Does anyone know how they get around the external domain access call??

thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Embedding forum using AJAX

Will <Nabble>
Administrator
I am a bit confused on what you are trying to do here. If you just want to embed your forum, then you can simply copy the embedding code and paste it into your html page. There is no special Ajax or whatever coding that you need to do on your part. But it seems that you want to do something else here, which I don't fully understand yet.
Reply | Threaded
Open this post in threaded view
|

Re: Embedding forum using AJAX

Democracy Monkey
Hi,

I will try to explain better :)

I basically have a website where the main menu links are loaded by an ajax call to dynamically load the target page in a container div. I have the +/- same functionality as this site from your examples: http://www.go-mono.com/ . Only the part below the main menu is loaded each time on clicks on a link from the main menu.

My Forum.html page contains:

<body>
The Democracy Monkey Discussion
<script src="http://n2.nabble.com/embed/f1464914"></script></body>

I have some ajax code that is called from this part of my index.html and should load Forum.html in the <div id="content">:

        <li>Forum</li>

The ajax is as follows:

  <script type="text/javascript"> var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no) var loadedobjects="" var rootdomain="" var bustcacheparameter="" function ajaxpage(url, containerid){ var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.onreadystatechange=function(){ loadpage(page_request, containerid) } if (bustcachevar) //if bust caching of external page bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime() page_request.open('GET', url+bustcacheparameter, true) page_request.send(null) } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) document.getElementById(containerid).innerHTML=page_request.responseText } function loadobjs(){ if (!document.getElementById) return for (i=0; i<arguments.length; i++){ var file=arguments[i] var fileref="" if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding if (file.indexOf(".js")!=-1){ //If object is a js file fileref=document.createElement('script') fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", file); } else if (file.indexOf(".css")!=-1){ //If object is a css file fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", file); } } if (fileref!=""){ document.getElementsByTagName("head").item(0).appendChild(fileref) loadedobjects+=file+" " //Remember this object as being already added to page } } } </script>


Maybe this is the wrong way to do things with nabble. It's rather late and I should have solved this by now, tiredness kills. What I ideally want to know is the functionality used by the example sites to dynamically load the embedded forum....... (i.e. put it in a div container like in go-mono without just displaying the link and without reloading the whole page)

thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: Embedding forum using AJAX

Democracy Monkey
apologies for forgetting to put escape chars to stop the auto generation of html..hope you understand anyways ;)
Reply | Threaded
Open this post in threaded view
|

Re: Embedding forum using AJAX

Hugo <Nabble>
As far as I can see, all examples in http://n2.nabble.com/help/Answer.jtp?id=36 and the go-mono web site use normal HTML (not Ajax) to load the embedded forum. You are the first user trying to load it by Ajax.

Note that the embedding javascript is composed by a link and a script tag. I see that your Ajax code supports a ".js" file. So you can create a js file that loads the forum using javascript. Example:
// First create a link
var link = document.createElement("a");
link.setAttribute("id", "nabblelink");
link.setAttribute("href", "http://n2.nabble.com/The-Democracy-Monkey-Discussion-f1464914.html"); 

// Then we create the script tag
var scr = document.createElement("script");
scr.setAttribute("type","text/javascript");
scr.setAttribute("src", "http://n2.nabble.com/embed/f1464914"); 
Please let me know if this solution works.

Regards,
Hugo Teixeira
Nabble.com