1
jQuery(document).ready(function() {
    jQuery('.bnr').each(function() {
        var group = jQuery(this).attr('adgroup');
        var obj = jQuery(this);
        jQuery.get("http://www.example.com/ads.php",
    { 'adGroup': group },
    function( response ) {
            obj.html( response );
        }
    );
    })
});

I'm trying to load ads using jQuery. The ads.php return affiliates code. Problem is when the return response is javascript. All works only if response is html. Using eval() do not work or i'm missing something. response example:

<script type="text/javascript" src="http://adserving.unibet.com/ad.aspx?pid=1234&pbg=123">

2 Answers 2

1

Use .load() to load dynamic content from a url

jQuery(document).ready(function() {
    jQuery('.bnr').each(function() {
        var group = jQuery(this).attr('adgroup');
        var obj = jQuery(this);

        obj.load("http://www.example.com/ads.php", { 'adGroup': group })
    })
});
Sign up to request clarification or add additional context in comments.

Comments

0

You can also try this way

 jQuery('.bnr').each(function() {
        var group = jQuery(this).attr('adgroup');
        var obj = jQuery(this);

       $.ajax({
           url: 'http://www.example.com/ads.php',
           data: { 'adGroup': group },
           dataType: "text/html", // this will make sure that your response is html 
           success: function(data){
             obj.html( data );
           }
       });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.