So this is what is happening. because my site is all jquery/ajax I thought added adbrites code to my site would be simple.
However what is happening is the following
I need to send a post request to the server to fetch the correct ad in this function that I am about to show, "it is case 90 that handles the ad." However every time it loads the ad it removes all the body code and places the ad in the whole body area.
If you don't know what adbrite code looks like it looks like this
<!-- Begin: AdBrite, Generated: 2011-12-04 2:47:16 -->
<script type="text/javascript">
var AdBrite_Title_Color = 'CC0000';
var AdBrite_Text_Color = '000000';
var AdBrite_Background_Color = 'FFFFFF';
var AdBrite_Border_Color = 'FFFFFF';
var AdBrite_URL_Color = 'CC0000';
try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';}
</script>
<script type="text/javascript">document.write(String.fromCharCode(60,83,67,82,73,80,84));document.write(' src="http://ads.adbrite.com/mb/text_group.php?sid=2059492&zs=3330305f323530&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));</script>
<div><a target="_top" href="http://www.adbrite.com/mb/commerce/purchase_form.php?opid=2059492&afsid=55544" style="font-weight:bold;font-family:Arial;font-size:13px;">Your Ad Here</a></div>
<!-- End: AdBrite Ads -->
Here is my jQuery code.
//send data to server
function fetch(e,formstring)
{
var a = 1;
$.ajax({
type: 'POST',
url: 'system/engine/core.php',
data: formstring,
dataType: 'json',
contentType: "application/x-www-form-urlencoded;charset=utf-8",
beforeSend: function() {
switch (e) {
case 2:
$("#content").html(" <div id='advertarea'></div>");
break;
case 400:
$('#searchresultssmall').html(" ");
break;
}
},
success: function(data){
$.each(data, function(i, obj) {
switch (e) {
case 1:
//Menu
links = obj.name.replace(/\s+/g, '-').toLowerCase();
$("ul#menu").append('<a href="/'+links+'"><li class="active">'
+obj.name
+'<li><a>');
break;
case 2:
links = obj.name.replace(/\s+/g, '-').toLowerCase();
$("#content").append('<a href="/'+links+'"><img class="catimages" src="'
+obj.picture
+'"/><a>');
//$("#content").html("hello");
break;
case 3:
$.each(obj, function(key, val) {
if(val != 0)
{
$("#usernametaken").html("<span style='color:red'><b>"+username+"</b> - is taken");
unamecheck = 0;
}
else
{
$("#usernametaken").html('<img src="theme/sysimages/tick.png"/><span style=" color: white;"><b>'+username+'</b> is valid</span');
unamecheck = 1;
}
unamecheck = val;
});
break;
case 4:
//LoginSript
$('#rightheader').html(obj.code);
break;
//advertismentarea
case 90:
$("#advertarea").html(""+obj.code+"");
break;
}
});
},
error: function(data){
$.each(data,function(i,myinfo){
//alert(i);
});
},
complete: function(){
//shownotify(2,"");
},
"text json": jQuery.parseJSON
});
return false;
}
Adbrite code uses document.write
js function...which should be called only while the document is loading. If you do it after, it will clear the document and then write the new content (ad)
Change the document.write
and jquery append
instead.
REPLACE
<script type="text/javascript">document.write(String.fromCharCode(60,83,67,82,73,80,84));document.write(' src="http://ads.adbrite.com/mb/text_group.php?sid=2059492&zs=3330305f323530&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));</script>
with this,
<script type="text/javascript">$('body').append( String.fromCharCode(60,83,67,82,73,80,84) + ' src="http://ads.adbrite.com/mb/text_group.php?sid=2059492&zs=3330305f323530&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">' + String.fromCharCode(60,47,83,67,82,73,80,84,62) );</script>
If you don't want/can't to modify the ad code, serve it within another iframe