douganggu4392 2014-05-15 10:25
浏览 87
已采纳

在jquery ui tabs中加载不同的页面很慢,有时会崩溃

My boss wanted different process (which were originally individual pages) to show up on tabs

anyway I'm using the jquery ui tabs

http://jqueryui.com/tabs/

my code

jquery

    <script type="text/javascript">
$(document).ready(function()
{ 
$("#tabs-1").load("transaction.php");
$("#tabs-2").load("book.php");
$("#tabs-3").load("schedule.php");
});
</script>

html

<ul>
<li><a href="#tabs-1">Transaction</a></li>
<li><a href="#tabs-2">Book</a></li>
<li><a href="#tabs-3">Schedule</a></li>
</ul>
<div id="tabs-1">
</div>
<div id="tabs-2">
</div>
<div id="tabs-3">

each page pulls up data in mysql database the problem is, book.php has lots of data so loading it is slow and sometimes the browser crashes

is this implementation possible or should I explain this that using tabs is not recommended, this should be showed using individual pages?

  • 写回答

1条回答 默认 最新

  • dshqd84261 2014-05-15 10:30
    关注

    what you could do is get the book.php to only load when tab 2 is clicked.

    $("#tabs-2").click(function(){
        $("#tabs-2").load("book.php");
    });
    

    this should help to stop it crashing straight away. if it doesn't help you will need to optimise you query.

    you could also try using ajax.

    put this in you document load and hopefully it should load the contents of book.php into the tab.

      $.get( "book.php", function(book) {
        $("#tabs-2").html(book);
      });
    

    Jquery Sample

    $.ajax({
       type: "POST",
       url: "page_url",
       data: $("#advserc").serialize() + "&pagenum=" + page, // i sent the page through with it
      beforeSend:function(){  // this unhides a div with gif loading image in it.
            //show gif here, eg:
            $("#loading").show();
    
        },
        complete:function(){
            //hide gif here, eg:
            $("#loading").hide(); // this hides the div
        },
       success: function(data){
          $("#content-container").html(data); // here i fill the div with the dat from the php page
       }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 求制作一个个人网页,
    • ¥15 寻涂色内存脚本作者有项目有市场有资源.却技术
    • ¥15 蓝桥杯c51单片机问题
    • ¥15 ajax跨域问题请求修改代码
    • ¥15 python matplotlib
    • ¥15 短信测压+语音,有偿,必须用Python
    • ¥20 COCOS2DX的protobuf协议注册函数问题
    • ¥15 (标签-Pytorch|关键词-Stream)
    • ¥15 求深圳2019年开放数据应用创新大赛的营运车辆数据!
    • ¥15 软件UI界面绘制折线图