Questions | Login

Top / Javascript / AJAX

Is it possible to detect when a request is sent by the browser and when an answer is posted?(with ja

demo 22 Dec 2008 02:35pm
I am using jQuery to pop up a dialog box that might contain different things from iframes to image to ajax...I need a way to detect when a request is sent and when the loading is completed ( the answer to the request) in order to create a "loading..." message that would work for any instance. with Ajax it is easy ( ajax status), so it is with an img ( onload action) but iframes I have no idea how to do it...besides it would be nice to have a universal approach for all instead of a specific one for each case. I figured since the browser itself knows when a request is sent ( hence the hour glass and the loading bar) there should be a way to read that...ideally in Javascript if possible...thank you for your help

Answers

demo 22 Dec 2008 05:31pm
Not sure why frame should be a problem. The tags that support onload events are:

body, frame (and iframe and frameset), img, link, and script

You can use embedded script tags to simulate onload for other elements that can contain script blocks. A simple example of this is:


<head>
<script type="text/javascript">
// simulate firing onload event for elements
// that don't support it
function publishEvent(evt, publisher) {
// for IE vs. non-IE browsers
evt = window.event?window.event:evt;
// get script block's parent
var el = publisher.parentNode;
// do whatever - could be to notify
// registered subscribers of events of
// given types fired by elements of
// given ids
alert(el.id + ':' + evt.type);
}
</script>
</head>
<body>
<div id="div0">
<!--
include.js doesn't need to do anything, but must exist
in order for onload event to fire
-->
<script
onload="publishEvent( event, this )"
src="include.js">
</script>
</div>
</body>
</html>

Related

Submit Answer

You must be logged in to post an answer. Please Login or Register.

Powered by phpMyAnswers.