开发者

Reload external script on link click

Is it possible to trigger a "refresh" for a div when you click a link? I have embedded a js call to an adserver in a div, there are a lot of parameters in the link so I couldn't get .load to work and this is the best solution I could come up with. Ideally, each time you click a link (change tab) I would like the script (ad content) to refresh and reload a different ad same as it does on page refresh. Is this possible with jquery?

HTML for links

<ul id="flowtabs">
    <li><a id="t1" href="#Brokers">Brokers</a></li>
    <li><a id="t2" href="#Education">Educators</a></li>
    <li><a id="t3" href="#Third-Party-Add-Ons">3rd Party Add-Ons</a></li>
    <li><a id="t4" href="#NinjaScript-Consultants">NinjaScript Consultants</a></li>
</ul>

ad container is

<div id="quoteContain">
<!-- AdSpeed.com Serving Code 7.9.5 for [Zone] Testimonial 200x600 -->
    <script type="text/javascript" src="http://g.adspeed.net/ad.php?do=js&amp;zid=XXXX&amp;wd=200&amp;ht=600&amp;target=_top"></script>
    <noscript><iframe width="200" height="600" src="http://g.adspeed.net/ad.php?do=html&amp;zid=XXXXXX&amp;wd=200&amp;ht=600&amp;target=_top" frameborder开发者_开发百科="0" scrolling="no"   >
    <a href="http://g.adspeed.net/ad.php?do=clk&amp;zid=XXXXXX&amp;wd=200&amp;ht=600&amp;pair=as" target="_top">
    <img style="border:0px;" src="http://g.adspeed.net/ad.php?do=img&amp;zid=XXXXXX&amp;wd=200&amp;ht=600&amp;pair=as" alt="i" width="200" height="600"/></a></iframe>
    </noscript><!-- AdSpeed.com End -->
<!-- /quoteContain --></div>

JS

$("ul#flowtabs li a").click(function){
    //need it to refresh here
    $("#quoteContain").html( data);
});


There's no such thing as "refreshing a div".

These are the components from the top of my head that can be "refreshed" (as in trigger a new request of data from their data source): images, css stylesheets, flash embeds etc.

You could try and "clone" this div, remove it from the dom, and add it again. But I'm not sure it will work.

var clone = $("#yourdiv").clone();
$("#yourdiv").replaceWith(clone);


Using jQuery loading content into the DOM is quite trivial.

function adContainerRefresh() {
    $('#adCoontainer').clear().load(adServerUrl);
}

$('foo').click(function () { 
    adContainerRefresh(); 
    /* ... */
});


Yes, it is possible updating the div (using ajax request).

an example without ajax:

<div id="xxx"></div>

if your new content is accessible over the net do something like

$('#xxx').load('/path/to/xxx.html');

in case your content to be inserted is delieverd using an ajax request - use the result and load it into the div or other html element

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜