javascript - event listener on an HTML element -
I am writing a web application that loads different page elements via AJAX call. I want to be able to trigger an load event when a certain element loads from an AJAX call, but I have all the elements DIV and are unable to trigger such incidents. Is there anything I can do? Can I add HTML files to trigger?
If you are using jQuery, you ready ()
event ( You can hear scripts on page (or loaded elements) after full loading (or loaded elements) on the page:
Your load page:
$ (Document) .ready (function () {// When the page (or loaded element) is fully loaded for action}};
This can help you better:
$ ("button"). Click (function () {$ .ajax ({url: "file_to_load Html", success: work (result, status, xhr) {warning ("Ajax request:" + xhr.status + "" + xhr.statusText); $ ("# Container"). Html (results);}});});
Success
parameter executes a function when the request is successful.
The maximum parameter result
contains the data returned from the server.
This will alert the "Ajax request: 200 OK" and then file_to_load.html Em> in # Container
.
Reference:
-
Ready ()
- -
. Ajax ()
-
Comments
Post a Comment