1

I have the following code:

var refreshId = setInterval(function()
{
    $("#footad").html('myjshere');
}, 15500);

Where it says myjshere I want to load this content into the div:

    <script type='text/javascript'>
      AdServer.placeAd({"sz":"728x90","pos":1});
    </script>

But when I try just having it where myjshere is, it throws out a syntax error?

Any help?


To clear up the confusion I was put the JavaScript where myjshere is I just used the word myjshere as a place holder to show you what I was doing. Sorry for the confusion. The issue is that when I put the javascript within the jQuery it does not work and returns an error: invalid syntax.


3
  • The issue is that when I put the javascript within the jQuery it does not work and returns an error: invalid syntax. Show us this code Commented Jun 15, 2012 at 11:14
  • var refreshId = setInterval(function() { $("#myjshere").html("<script type='text/javascript'> AdServer.placeAd({'sz':'728x90','pos':1});</script>"); }, 15500); Commented Jun 15, 2012 at 11:15
  • If the function returns a HTML string then my first code snippet should do the trick. Commented Jun 15, 2012 at 11:18

5 Answers 5

1

What your script is doing is putting 'myjshere' into the element with id 'footad' .

Is that what you are trying to achieve?

If I understood right, what you want, then this is the code:

var refreshId = setInterval(function()
{
    $("#myjshere").html("<script type='text/javascript'>     AdServer.placeAd({'sz':'728x90','pos':1});</script>");
}, 15500);

Else if you want to replace myshere

var refreshId = setInterval(function()
{
    $("#footad").replace("myjshere","<script type='text/javascript'>     AdServer.placeAd({'sz':'728x90','pos':1});</script>");
}, 15500);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I guess I had forgot to escape a character.
In the end I switched to Iframes as this was being difficult... and I am lazy, but thanks again :)
1

I'm assuming AdServer.placeAd is a third-party function you want to implement. Therefore it depends on what the output of this function is. If Adserver.placeAd returns a HTML string you could do the following:

<script type='text/javascript'>
var refreshId = setInterval(function()
{
   $("#footad").html(AdServer.placeAd({"sz":"728x90","pos":1}));
}, 15500);
</script>

My guess is that this code is running document.write() inside the function seeing as its called placeAd. Therefore you could add the code into the part of the HTML document you want it to appear like:

<script type='text/javascript'>
setInterval(function()
{
   AdServer.placeAd({"sz":"728x90","pos":1});
}, 15500);
</script>

1 Comment

Please see edit, sorry if I confused you. It is returning a html string, but I am using this technique as part of an auto refresh system, so it would need to be done where the whole div is updated.
0

i better dont aks why you want to do this....

$('#footad').html('<script type="text/javascript">
AdServer.placeAd({"sz":"728x90","pos":1});
</script>');

Comments

0

do you want to see the js as plain text you can load it with:

var js = AdServer.placeAd({"sz":"728x90","pos":1});
$("footad").html(js);

but will the js function placeAd return html? if not you must give an target to the AdServe class. like Adserver.target("#footad");

if this all is not that what you need, you must give more informations.

Comments

0

You need to do it like this

<script type='text/javascript'>

     var myjshere = AdServer.placeAd({"sz":"728x90","pos":1});
     $(document).ready(function(){
        setInterval(function()  {
             $("#footad").html(myjshere);
          }, 15500);
     });

</script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.