Flamingo.Ajax.processHTMLString()

The processHTMLString() method can be used in the callback function of AJAX requests. The function will process HTML string it gets from the server according to the templates order and conditions. As a result, it returns a new converted HTML string to the callback function which can render the result.

Syntax

Flamingo.ajax.processHTMLString(url, htmlString, callback)

Parameters

Parameter Type Description
url String URL of the page by which a template will be detected.
htmlString String HTML of the original page that should be processed.
callback String The callback function is called right after conversion is completed. It takes the converted HTML as an argument.

Example

The following example finds an element with id=’ajaxContent’ and processes its content.

function render(html){
   document.getElementById('ajaxContent').innerHTML = html;
};
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com/ajaxcontent.html', true);
xhr.onload = function() {
   Flamingo.Ajax.processHTMLString('http://example.com/ajaxcontent.html', this.responseText, render);
}
xhr.send();

After sending the Ajax query to http://example.com/ajaxcontent.html and getting an answer, the answer will be converted and the code received after conversion will be inserted into an element with id=’ajaxContent’.

See also