reloadFromUrl: Insert HTML from an External URL
This simple little script allows a link to a file to be replaced by the contents of the file using AJAX.
Replacing a Hyperlink with its Linked Content
In the example below the link to "reloadFromUrl.xml" is used to get the contents of that file using AJAX.
The contents are then inserted in the spot where the link was.
Loading the Content Automatically
In the example below this link is loaded automatically.
The optional "interval" class name enables a refresh loop.
Replacing Specific Content
The following links will insert just one of a few specific segments of the linked file, indicated by an ID:
- Contents of the element named "insertFragmentA" from "reloadFromUrl.xml".
- Contents of the element named "insertFragmentB" from "reloadFromUrl.xml".
- Continually refresh the contents of "reloadFromUrl.xml".
Posting a Form Using AJAX
Using this same method the values of a form can also be submitted with the new content.
By replacing selective ID's, forms can be validated using the server-side code.
Required Files
-
jQuery Addon Script: jquery.classbehaviours.reloadfromurl.js
- Prerequisite Script: jquery.classbehaviours.js
- Example Markup: reloadFromUrl.html
- Example XML: reloadFromUrl.xml
- Example Stylesheet: reloadFromUrl.css
Comments on this Article