import DOMReplaceWithSameElementFromUrl from 'ievv_jsbase/lib/dom/DOMReplaceWithSameElementFromUrl'DOMReplaceWithSameElementFromUrl
Extends:
Extends DOMReplaceFromUrl to replace the element with the same element from the server response.
This is intended to be used if you request a full page from the server to replace a single element in your document.
Example
Lets say you have a /pages/test that produce the following HTML:
<html>
<body>
<div id="id_something">
Initial data.
</div>
</body>
</html>
And you would like to replace the current content of the id_something element
with updated data from the server:
let domReplace = new DOMReplaceWithSameElementFromUrl('id_something');
domReplace.replaceInnerHtml('/pages/test')
.then((htmlString, response) => {
console.log(
`successfully replaced the current content of id_something with: ${htmlString}`);
console.log(`The full response from the server was: ${response.toString()}`);
})
.catch((error) => {
console.error(`An error occurred: ${error.toString()}`);
});
Method Summary
| Public Methods | ||
| public |
extractHtmlStringFromResponse(response: *): string Overridden to extract the innerHTML of the element with ID matching DOMReplaceWithSameElementFromUrl.elementId. |
|
Inherited Summary
| From class DOMReplace | ||
| public |
The DOM element. |
|
| public |
The element DOM ID. |
|
| public |
appendInnerHtml(htmlString: string) Append innerHTML to the element. |
|
| public |
prependInnerHtml(htmlString: string) Prepend innerHTML to the element. |
|
| public |
replaceInnerHtml(htmlString: string) Replace innerHTML of the element. |
|
| From class DOMReplaceFromUrl | ||
| public |
appendInnerHtml(url: string): Promise Append to the innerHTML of the element with data from a GET request to an URL. |
|
| public |
extractHtmlStringFromResponse(response: *): * |
|
| public |
prependInnerHtml(url: string): Promise Prepend to the innerHTML of the element with data from a GET request to an URL. |
|
| public |
replaceInnerHtml(url: string): Promise Replace innerHTML of the element with data from a GET request to an URL. |
|
Public Methods
public extractHtmlStringFromResponse(response: *): string source
Overridden to extract the innerHTML of the element with ID matching DOMReplaceWithSameElementFromUrl.elementId.
Params:
| Name | Type | Attribute | Description |
| response | * |