简体   繁体   English

其他Ajax中的Ajax请求

[英]Ajax request inside an other ajax

So i made an ajax request for get my "home" page and my "about" page in a "container" on click menu link button inside my index.php, and now i have three link in my "home" page, and i also want open each of these links inside my div "container" to replace the "home" page, so how can i make an ajax request after the first ajax call ? 所以我提出了一个ajax请求,将index.php内的“菜单”链接按钮上的“主页”页面和“关于”页面放在“容器”中,现在我的“主页”页面中有三个链接,还希望在div“容器”中打开这些链接中的每个链接以替换“主页”页面,因此,在第一次ajax调用之后如何发出ajax请求?

This is my php request in the index.php: 这是我在index.php中的php请求:

 <div id="container"> <?php $d="contenu/"; if(isset($_GET['p'])){ $p=strtolower($_GET['p']); if(preg_match("/^[a-z0-9\\-]+$/",$p) && file_exists($d.$p.".html")){ include $d.$p.".html"; } else{ include "pages/404.html"; } } else{ include "pages/home.html"; } ?> </div> 

In here my ajax: 在这里我的ajax:

 $(document).ready(function(){ $("#menu a").click(function(){ page=$(this).attr("href"); $.ajax({ url: "pages/"+page, cache:false, success:function(html){ afficher(html); }, error:function(XMLHttpRequest,textStatus, errorThrown){ afficher("erreur lors du chagement de la page"); } }); return false; }); }); function afficher(data){ $("#container").fadeOut(500,function(){ $("#container").empty(); $("#container").append(data); $("#container").fadeIn(1200); }); } 

and finally my home.html ( i just show you the links ): 最后是我的home.html(我只向您显示链接):

 <div class="section vs-section" data-speed="0.4"> <div class="vs-transform title " data-speed="0.4"><a href="projet1.html"><h3>projet1</h3></a></div> <div class="vs-transform title" data-speed="0.38"><a href="projet2.html"><h3>Projet2</h3></a></div> <div class="vs-transform title" data-speed="0.4"><a href="projet3.html"><h3>projet3</h3></a></div> </div> 

Yes you can, you should just use event delegation on() to deal with the new HTML tags added dynamically to the DOM by the first ajax request : 是的,您可以使用事件委托on()来处理由第一个ajax请求动态添加到DOM的新HTML标签:

$('body').on('click', '.vs-transform a', function(){
     //Second ajax request
})

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM