weixin_33704234 2011-12-08 06:46 采纳率: 0%
浏览 10

ajaxStop不在DOM元素上

I have a program that, given an array of youtube video ids, calls the Youtube API and returns data about said videos. I do this by calling:

$.getScript("http://gdata.youtube.com/feeds/api/videos/"+encodeURIComponent(id)+"?v=2&alt=json-in-script&callback=youtubeFeedCallback");

This is done for each video id in the array. Is there a way to use ajaxStop to then do something (in my case modifying the DOM) once all of these requests finish? I am not doing this on any sort of .click or .mouseover or other such event, these requests are simply sent out when the page is loaded. I tried to do:

$.ajaxStop(function () { (do something here) });

But I got the following error: Uncaught TypeError: Object function (a,b){return new e.fn.init(a,b,h)} has no method 'ajaxStop'. Also will this work if some of the requests return 403 Forbiddens?

Edit: SOLVED

Fixed it, although my solution is a bit hacky. Instead of using $.getScript I instead just used the $.ajax function. I then had a global counter variable, and using the "error" method of $.ajax, incremented the count on error or on success. Then I just called what I wanted to when the count variable was equal to the length of my array. Id still love to hear if there is a better way to do this.

  • 写回答

2条回答 默认 最新

  • weixin_33676492 2011-12-08 06:53
    关注

    Try using the ajaxComplete event. There is a jQuery method for it. http://api.jquery.com/ajaxComplete/

    You may need to count the amount of requests so you know when all of them are complete.

    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试