Load a PHP page’s div on another page on other domain

Goodmorning,
I’ve this situation:

I’m working with WordPress and I’m trying to create an affiliate box for our affiliates. I’ve created it dynamically and you can see one example here

Read More

Values for the creation of the box are passed with $_GET and the box is created by a php function called before the_content() on the template page.

The box, if you load the page directly, works fine.

But I’m trying to load that specific div into another page and for test I’m trying to load it into a page of my same domain.

The page for the test is here

I’m using jQuery load() function for the loading, like this:

jQuery(document).ready(function(){
   var valore = jQuery('#cm_aff_box_container').text();
   jQuery('#cm_aff_box_container').empty().load('http://www.clubmagellano.it/affiliate-box/?value='+valore+' #cm_affiliate_box', function(){/*Other stuff here*/});
    });     
});

Unfortunately it won’t load anything in the div. I’ve tried to load the page directly and it loads correctly despite the fact that also in this case my affiliate box is not loaded.

I’ve also read that the load() function won’t work for other domains and I need that portability. How can I solve this problem?

==========UPDATE===========

I’ve resolved, and the box is loaded within my domain. The problem is, how can I load it on another domain?

==========UPDATE 2.0 ===========

Guys I’ve resolved putting this:

<?php header("Access-Control-Allow-Origin: *"); ?>

To the header.php file of the domain which create the box. It works perfectly!

Related posts

Leave a Reply

2 comments

  1. Why not use an iframe? It’s typically used to display ads in a page.

    <iframe id="cm_affiliate_box"></iframe>
    
    .
    .
    .
    
    jQuery(document).ready(function(){
       jQuery('#cm_affiliate_box').attr('src', 'http://www.clubmagellano.it/affiliate-box/?value='+valore+' #cm_affiliate_box');     
    });
    
  2. If everyone is having this problem follow this solution:

    Put this code to the header.php of your domain template, the domain which has to be loaded.

    <?php header("Access-Control-Allow-Origin: *"); ?>
    

    The load() jQuery function will recognize as trusted the website and will load the box. It’s perfectly working!

    If you don’t want to allow all domains but only some, instead of ‘*’ you could write the link of domain/s allowed to retrive the box.