2

Is there some event that fires when an ajax request is completed? Even if it's not standard, as long it works on Firefox or Google Chrome.

Note: I didn't start the request, "someone else" did. It is not using jQuery.


The reason I want this is because websites like facebook aren't updating the whole page, so it doesn't fire the window.onload. This is becoming an issue to develop addons. It is hard to check the page and inject the script. If there were some event like window.onajaxcompleted it would be easier to inject the scripts.

I know there is one event that check for DOM changes, that is not exactly what I need, but it is one workaround.

Community
  • 1
  • 1
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
  • @Felix: I wanted to sound like "I don't know how the request is being done, it can be anything". But I changed to be more clear. – BrunoLM Jan 19 '11 at 23:03
  • 1
    So you're looking for an event that fires when *any* XMLHttpRequest object completes? – Jacob Jan 19 '11 at 23:06
  • "Ajax" means "Making an HTTP request using JavaScript". Any event depends on the method used to perform the task, not the task itself. – Quentin Jan 19 '11 at 23:07
  • What is your script doing? I.e. why does it have to know about new elements? Maybe there is another way to solve this. – Felix Kling Jan 19 '11 at 23:44
  • @Felix change the page html (lets say: convert text links to html links) is one thing. I can't change on the `onload` event, because it is updated partially. – BrunoLM Jan 20 '11 at 01:40
  • Related: http://stackoverflow.com/q/4535531/340760 – BrunoLM Jan 20 '11 at 23:11
  • If you're doing this from a Firefox addon then I believe you can trace all network activity and I think eventually relate it back to a window; if that's the window you're interested in you can then schedule a callback to perform the task. – Neil Jan 26 '11 at 00:33

1 Answers1

1
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     alert('Success');
    }
  }
worenga
  • 5,776
  • 2
  • 28
  • 50