jQuery多个ajax调用 [英] Jquery Multiple ajax call

查看:136
本文介绍了jQuery多个ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列出的带有字母的导航,当用户单击字母时,我试图从不同的json文件中调用演员和导演.我使用了2个ajax调用来从actor.php和director.php获取数据.它在我的本地计算机上运行良好,但只有第一个在服务器上运行.如何使每个Ajax调用正常工作?

I have a listed navigation with letters and i am trying to call the actors and directors from different json files when the user clicked a letter. I used 2 ajax calls to get the data from actor.php and director.php. It works fine on my local machine, but only the first one works on server. How can i make each ajax calls working?

$(document).ready(function(){
    $('.letters').click( function(){
         var letter=$(this).html();

     $.ajax({
       url: 'actor.php?harf='+letter,
       dataType: 'json',
       success: function(JSON) 
                 {  //some code   }
               }); 


     $.ajax({
       url: 'director.php?harf='+letter,
       dataType: 'json',
       success: function(JSON) 
              {  // some code     }
     }); });  });

推荐答案

如果执行此操作会发生什么:

What happens if you do this:

$.ajax({
   url: 'actor.php?harf='+letter,
   dataType: 'json',
   success: function(JSON) {  
     //some code   
     $.ajax({
       url: 'director.php?harf='+letter,
       dataType: 'json',
       success: function(JSON) {
         // some code
       }
     });
   });
});

我不会冒险背靠背堆积2个Ajax调用.

Piling up 2 ajax invocations back-to-back is not something I would risk.

这篇关于jQuery多个ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆