doudou20080720 2013-09-09 15:24
浏览 26
已采纳

使用jquery和ajax包含或附加许多php页面

I have a page with a div tag like this

<div class="ajax-load">

<!-- First.php: jquery-slider-1
            jquery-widget-1

    second.php: jquery-slider-2
                jquery-widget-2
 -->

</div>

And a button like this

<button class="go-to-page-2">

When I click the button with class go-to-page2 I need to load some php pages say four.php and five.php into or inside the div with class ajax-load.

Using plain markup, I can easily place it like this

<?php
    require_once("four.php");
    require_once("five.php");
?>

But I do not want this. I want to load contents into the div using ajax. I tried this:

 $(".ajax-load").load("4.php")

But cant load or append 5.php using this. How to overcome this? I am ready to use $.get and $.post

  • 写回答

3条回答 默认 最新

  • douyimin1083 2013-09-09 15:29
    关注

    .load() replaces the contents of the target element with whatever you loaded. You'd need to load page4, then APPEND page5, e.g.

    $(".ajax-load").load("4.php");
    $.get('5.php', function(data) {
       $('.ajax-load').innerHTML += data;
    });
    

    As well, note that since this will involve TWO separate http requests, there is NO guarantee as to which of the two requests will come back first. If loading 4.php before 5.php is absolutely critical, you'll have to chain the requests to so that the request for 5.php goes out only after 4.php has completed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口