views:

134

answers:

2

When dynamically inserting an iframe into a webpage, the JQuery load event allows me to trigger a callback function when this iframe is loaded (see also this stackoverflow article).

The problem I am struggling with, is that I want to do something when the src request is sent to the server but before the response is received from that server. In other words, I am looking for an event like "request fired". The JQuery load event doesn't seem to help here.

I have been playing with several values for the JQuery setTimeout method, but that doesn't look like a very robust solution to me.

+2  A: 

I am not sure why you would need that event. When you call the JQuery method, you know the request is being made so you would call your method there.

epascarello
I agree. @Matthijs, can you explain why you are looking for a little more clearly. It sounds like the request would be sent immediately when you insert the iframe.
Prestaul
+1  A: 

The iframe loads the "src" url as soon as its added to the document.body.

var iframe = document.createElement("iframe");
iframe.src = "http://somesite.com";

document.body.appendChild(iframe);
// request fired, your code would go here
Luca Matteis