simpleRequest is a simple JavaScript object that can help you to make requests in a simple way.
Juste check following demos :
Perform a GET request to get external content for example.
Syntax :
sJS.get('url', function(err, res) {
// When no errors
if(!err) {
// .. do something
} else {
// .. do something else when an error occured
}
});
Perform a GET request, and parse the JSON so you can access to all elements in a easy way with JavaScript.
Syntax :
sJS.getJSON('url', function(err, res) {
// When no errors
if(!err) {
// .. do something
} else {
// .. do something else when an error occured
}
});
See results in the console after clicking on the 'Run' button
Example :
document.getElementById('demo3-run').addEventListener('click', function () {
document.getElementById('demo3-zone').appendChilds(
sJS.newElem('p', {
className: 'test',
textContent: 'This is a paragraph for a test :p'
}),
sJS.newElem('div', {
className: 'myClass',
innerHTML: 'Hello world ! :)'
})
);
});
New elements will append here ! Click on the 'Run' button !
Example :
document.getElementById('demo4-run').addEventListener('click', function () {
var firstP = document.getElementById('demo4-zone').querySelector('p');
sJS.removeElem(firstP);
});
Note that you can also use the element.remove() method
Click on the 'Run' button ! To remove me !
I'll be removed after ;)
I'll be removed after the second^^
I'll be removed after the 3rd :P
You can view the source code of this page if you want to see how you can use these functions