//insert a script tag with the provided URL
MauticJS.insertScript('http://google.com/ga.js');
//wrapper around console.log
MauticJS.log('Something happened');
//transform an object properties into a key=value string
var obj = {firstname: "John", lastname: "Doe"};
var serialized = MauticJS.serialize(obj); // Shows "firstname=John&lastname=Doe"
//document ready
function ready() {
alert('test');
}
MauticJS.documentReady(ready);
/**
* Ajax
*/
//XMLHttpRequest: CORS Request
MauticJS.createCORSRequest('GET', 'https://mymautic.com/dwc/slot1');
//open a cross domain request to the specified URL
MauticJS.makeCORSRequest('GET', 'https://mymautic.com/dwc/slot1', [], function (response, xhr) {
if (response.success) {
document.getElementById('slot1').innerHTML = response.content;
}
});
//take a text string and check to see if it is a valid JSON string
var text = '{"firstname": "John", "lastname": "Doe"}';
var json = MauticJS.parseTextToJSON(text);
alert(json); // Will show [object Object]
var text = 'not valid json';
var json = MauticJS.parseTextToJSON(text);
alert(json); // Will show 'not valid json'