Permalink
Browse files

fix cross-site xhr issue in spc tag

  • Loading branch information...
1 parent 822dc85 commit aa62de60aaac71b04033eed905451853e712b8dd @kolyuchiy kolyuchiy committed Aug 2, 2011
Showing with 13 additions and 7 deletions.
  1. +7 −4 README.md
  2. +6 −3 src/jquery.openxtag.js
View
@@ -92,7 +92,7 @@ Requirements
TODO
----
- * FIX cross-site xhr
+ * fix cross-site xhr
* add documentation on plugins.jquery.com
* add test suite
* remove callback, add event on ad load
@@ -103,12 +103,15 @@ TODO
Known issues
------------
-The plugin send requests to OpenX server using XHR. Because of that cross-site
-requests may not work due to same-origin policy. Possible workarounds are:
+The plugin sends js tag requests to OpenX server using XHR. Because of that
+cross-site requests may not work due to same-origin policy. Possible
+workarounds are:
+ * Use iframe or spc type tags. SPC (Single Page Call) is recommended.
* Setup server-side XHR proxy on same domain that your ad tag requests
originate from.
- * Use iFrame type tags.
* Add Access-Control-Allow-Origin response header in your OpenX web server
configuration (not all browsers support this header).
+When you work with OpenX, don't forget to disable AdBlock.
+
View
@@ -306,18 +306,21 @@
var data = _buildStandardRequestParameters(thesettings);
data['zones'] = $.map(zones, function (id, name) { return name + '=' + id; }).join('|');
data['nz'] = 1; // named zones
- data['r'] = Math.floor(Math.random()*99999999999);
var scriptURL = (location.protocol == 'https:' ? thesettings['deliverySSL'] : thesettings['delivery']) + '/' + thesettings['spcTagScript'];
var that = this;
$.ajax({
url: scriptURL,
data: data,
- dataType: 'html',
- async: thesettings['forceAsync'], // should be disabled for block(campaign)
+ dataType: 'script',
success: function (data) {
var flJsURL = (location.protocol == 'https:' ? thesettings['deliverySSL'] : thesettings['delivery']) + '/' + thesettings['swfObjectJS'];
$.getScript(flJsURL, function () {
+
+ // do eval here to work around potential problems when two
+ // requests are run in parallel and one OA_output
+ // overwrites another OA_output in global context
+
var output = eval('(function () {' + data + ';return ' + thesettings['jsPrefix'] + 'output;})()');
that.each(function () {
var $this = $(this);

0 comments on commit aa62de6

Please sign in to comment.