weixin_33705053 2015-02-15 14:38 采纳率: 0%
浏览 19

使用AJAX打开引导程序选项卡

I want to open bootstrap tabs and instantly show the href page inside each tab onclick. I have this small code below but it does not output any page.

html

<div id="tabs">
    <ul class="nav nav-tabs" id="prodTabs">
        <li class="active"><a href="#tab_basic" data-url="http://localhost/bioinformatica/stuff/pagina.html">Basic</a></li>
        <li><a href="#tab_images" data-url="httpt://localhost/bioinformatica/stuff/pagina.html">pagina</a></li>
        <li><a href="#tab_videos" data-url="www.facebook.com">FB</a></li>
    </ul>
    <div class="tab-content">
        <div id="tab_basic" class="tab-pane active"></div>
        <div id="tab_images" class="tab-pane active"></div>
        <div id="tab_videos" class="tab-pane active"></div>
    </div>
</div>

Javascript

$('#tabs a').click(function (e) {
    e.preventDefault();

    var url = $(this).attr("data-url");
    var href = this.hash;  
    var pane = $(this);

    // ajax load from data-url

    $(href).load(url,function(result){      
        pane.tab('show');
    });
});

// load first tab content
$('#tab_basic').load($('.active a').attr("data-url"),function(result){
  $('.active a').tab('show');
});
  • 写回答

1条回答 默认 最新

  • ℡Wang Yan 2015-02-15 14:55
    关注

    You need to prepend http:// in the data-url or else the code will append the domain where it is already running.

    Also, even after prepending http:// it is not gonna work because of Cross Domain Request. Dont worry your code is fine, it is just that http://google.com doesn't allow any other to make an AJAX request to it.

    Just try it with some file already present on your local server.

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?