ads included by ajax

Status
Not open for further replies.

agustinvinao

New Member
Messages
18
Reaction score
0
Points
0
Hi, im new in the host and i want to call de ads by ajax.

The javscript code is this:
HTML:
            function CreateAjax() {
                var xRequest=null;
                if (window.XMLHttpRequest) {
                    xRequest=new XMLHttpRequest();
                }else if (typeof ActiveXObject != "undefined"){
                    xRequest=new ActiveXObject("Microsoft.XMLHTTP");
                }
                return xRequest;
            }
            
            function GetHostedBy(){
                try{
                    GetHTML(\'\hosted_by.php\',1,\'\',\'hosted\');
                }catch(e){
                }
            }
            function GetHTML(_url,_action,_parameter,_div){
                // create obj ajax
                var ajax = CreateAjax();
                // get info
                ajax.open(\'get\', _url+\'?\'+ _parameter);
                ajax.onreadystatechange = function () {
                    if(ajax.readyState == 4){
                        var response = ajax.responseText;
                        document.getElementById(_div).innerHTML ="";
                        document.getElementById(_div).innerHTML = ajax.responseText;
                    }
                }// end readystate
                ajax.send(null); 
                delete ajax;
            }
Code for hosted_by.php:
PHP:
<?php include('http://staff.x10hosting.com/adCode.php?ad=advanced');
In the page i add a span:

HTML:
<span id="hosted"></span>

Functioning ok, but no resoult is display, i think is because the call is asynchronous and the javascript is not executed. The answer in the ajax response is this:
HTML:
 <script language="JavaScript" type="text/javascript">
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);
   
   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://x10hosting.com/advert/adjs.php?n=" + phpAds_random);
   document.write ("&what=zone:3&target=_blank");
   document.write ("&exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->

</script><noscript><a href='http://x10hosting.com/advert/adclick.php?n=a915c788' target='_blank'><img src='http://x10hosting.com/advert/adview.php?what=zone:3&n=a915c788' border='0' alt='' /></a></noscript>
If you see in the <A> tag is emty in the text to show.
I like to do this because my site display slow because the call to de ads in a moment on high calls to this ads, i test this calls to a page with yhe ads and to other pages with no ads and the result is a difference in the load time. In the first test the page is view in the instant and the second test display in five second of load.

Sorry for my english but im argentine.
 

agustinvinao

New Member
Messages
18
Reaction score
0
Points
0
I find a solution to this, but i need the approval of the admin.
The solution is this:

The code
PHP:
include('http://staff.x10hosting.com/adCode.php?ad=advanced');
return a javascript:

HTML:
<script language="JavaScript" type="text/javascript">
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://x10hosting.com/advert/adjs.php?n=" + phpAds_random);
   document.write ("&what=zone:3&target=_blank");
   document.write ("&exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->
</script>
This code call a php page (http://x10hosting.com/advert/adjs.php) with a dinamics parameters, ok, in this point i make my changes, i put this javascript in my page, and i call the php page (adjs.php) by ajax, with de correct parameters.

The result is the same when call
PHP:
include('http://staff.x10hosting.com/adCode.php?ad=advanced');
But in this way i give result while the ads is calling, and my site is put faster.
If you see in the botton of my site, is a leyend "Loading ads..." and when the call to Ads page finished change to de Ads result.

Please, give me feedback to this, if you need some explanation of this, send me a pm.

Sorry for my english again.

Agustin.
 
Status
Not open for further replies.
Top