PHP ajax的open属性,ajaxloading openx with jquery and php

问题

after a long journey I managed to ajax-load my openx-ads with a combination of jquery an php.

You need is

an openx-server on your own and access to /{openxPath}/www/delivery/alocal.php.

a little wrapper that makes the ad-script ajaxable

an ajax-loader

The third and easiest part is the ajax-loader:

$(document).ready( function() {

$.ajax({

url: "http://{urlToYourOpenxWrapper/adwrapper.php",

type: "POST",

data: {m:'f'}, // 'code' of ad to load

async: false,

dataType: 'html'

}).done(function (answer) {

$('#footerBanner').html(answer);

});

});

The second part is a little bit tricky an maybe not future-proof. But for 2.8.11 it is working.

For security reasons I made a mapping from characters to zone-ids. I don't know if this is really necessary.

adwrapper.php:

define('MAX_PATH', 'pathToYoutOpenXServer');

if (@include_once(MAX_PATH . '/www/delivery/alocal.php')) {

if (!isset($phpAds_context)) {

$phpAds_context = array();

}

switch ($_POST["m"]) {

case 'f': // code of the ad to load

$zoneId = 12;

$bannerTarget = 'footerBanner zone_' . $zoneId;

$bannerCode = view_local('', 12, 0, 0, '', '', '0', $phpAds_context, '');

break;

}

// get banner id

$regex = '/(.*)(ox_[^\']*)(.*)/';

preg_match($regex, $bannerCode['html'], $matches);

$oxId = $matches[2];

// compile new insert code

$replaceWith = '$("' . $oxId . '").after';

$banner = str_replace('document.write', $replaceWith, $bannerCode['html']);

$banner = str_replace('' ,

'' ,

$banner);

// use a single object for each ad to prevent problem in multitasking

$banner = str_replace('ox_swf', 'ox_swf_' . $zoneId, $banner);

// sometime the oxId (unique Id???) is the same and than zones are mixed

// so I append the zoneId to the oxId

$banner = str_replace($oxId, $oxId . '_' . $zoneId, $banner);

echo '

' . $banner . '
';

}

回答1:

Thanks, working on it and fail fail fail, but great solution from you !

I just need using GET request and must add on the php wrapper

header("Access-Control-Allow-Origin: *");

header("Access-Control-Request-Method: GET");

来源:https://stackoverflow.com/questions/18955887/ajaxloading-openx-with-jquery-and-php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值