VincentG Posted February 7, 2008 Share Posted February 7, 2008 Hi all, I pretty new with ajax and javascript and have a problem. On my site, I have some tabs to switch between several types of content, like news, articles, media and all. An ajax scripts includes the result of a php script. The php script gets some data from the database and shows the results (the last 30 rows). After 10 rows, I want to display a banner. The banner is displayed by a javascript code. I tried something with the oncomplete function, but my ajax and javascript knowledge is too low to get the result I want. The code where the tabs are shown and the ajax code places the result of the php file in the headlines_ajax div: <script> var objHeadlines; function headlines(type) { var pagina = "ajax_headlines.php?tijd=" + Date() + "&type=" + type; objHeadlines = createRequestObject(); objHeadlines.open("GET", pagina, true); objHeadlines.onreadystatechange = headlinesDiv; objHeadlines.setRequestHeader("Cache-Control", "no-cache"); objHeadlines.setRequestHeader("X_USERAGENT", "AjaxApplicatie"); objHeadlines.send(null); } function headlinesDiv() { if (objHeadlines.readyState == 4 && objHeadlines.status == 200) { if (objHeadlines.responseText) { document.getElementById("headlines_ajax").innerHTML = objHeadlines.responseText; } } } </script> <div class="boxTabsH"> <div id="tabHeadlines" class="tabHAlles"></div> <div class="boxTabH6"></div> <div class="boxTabH1" onClick="document.getElementById('tabHeadlines').className = 'tabHAlles'; headlines('alles');" onMouseOver="this.style.cursor='pointer';" onMouseOut="this.style.cursor='default';"></div> <div class="boxTabH2" onClick="document.getElementById('tabHeadlines').className = 'tabHNieuws'; headlines('nieuws');" onMouseOver="this.style.cursor='pointer';" onMouseOut="this.style.cursor='default';"></div> <div class="boxTabH3" onClick="document.getElementById('tabHeadlines').className = 'tabHArtikelen'; headlines('artikelen');" onMouseOver="this.style.cursor='pointer';" onMouseOut="this.style.cursor='default';"></div> <div class="boxTabH4" onClick="document.getElementById('tabHeadlines').className = 'tabHVideos'; headlines('videos');" onMouseOver="this.style.cursor='pointer';" onMouseOut="this.style.cursor='default';"></div> <div class="boxTabH5" onClick="document.getElementById('tabHeadlines').className = 'tabHScreens'; headlines('screens');" onMouseOver="this.style.cursor='pointer';" onMouseOut="this.style.cursor='default';"></div> </div> <div id="headlines_ajax"> </div> In the PHP file, the code counts the results and after 10 rows of the 30, the banner should be placed. <?php // some code for getting the data out of the database is removed if ($bannerCount == 10) { $betweenItems = true; ?> <div id="bannerCenter" class="bannerCenter"> <script language="JavaScript" type="text/javascript"> if (typeof(et_ord)=='undefined') et_ord=Math.floor(Math.random()*10000000000000000); if (typeof(et_tile)=='undefined') et_tile=1; document.write('<scr'+'ipt language="JavaScript" src="http://ad.uk.doubleclick.net/adj/dqa.domain.ext/rectangle;sz=336x280;tile=' + (et_tile++) + ';ord=' + et_ord + '?" type="text/javascript"></scr' + 'ipt>'); </script> </div> <script language="JavaScript" type="text/javascript"> function showBannerCenter() { if (document.getElementById('bannerCenter').clientHeight <= 14) { document.getElementById("skinBoxItemAdd").style.display = 'none'; document.getElementById("bannerCenter").style.display = 'none'; } } </script> <?php } // some code for displaying the results is removed ?> Hopefully someone can help me with this. Quote Link to comment Share on other sites More sharing options...
haku Posted February 7, 2008 Share Posted February 7, 2008 Help you with what? There was no question or description of the problem. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted February 7, 2008 Share Posted February 7, 2008 you can not return javascript through ajax and then innerHTML it into something. The javascript will not execute because innerHTML does not understand javascript. javascript returned through ajax can only be executed by running it through the eval() function. That does not work however with a script tag with a src= attribute, and document.write does not work that way either, so there would be many problems in getting a doubleclick banner like that to work as a ajax return value. I assume the script returned from doubleclick has more document.writes in it as well so that means even more problems. Quote Link to comment Share on other sites More sharing options...
VincentG Posted February 8, 2008 Author Share Posted February 8, 2008 Thanks. I removed the ajax part in it. A complete page refresh is needed, but is not the biggest problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.