Ajax module examples

Examples for the Ajax modules

by Imabot

HTML

More details on my blog: <a href="https://lucidar.me/en/javascript-modules/ajax/" target="_blank">https://lucidar.me/en/javascript-modules/ajax/</a>

<h1>Ajax example</h1>

</p>
<!-- Success or failure -->
<div id="failure"></div>

<!-- Response -->
<b>Response:</b> <span id="response"></span>

CSS

#failure { color:red; }

JavaScript

import {ajax} from 'https://lucidar.me/en/javascript-modules/files/ajax.min.js'

ajax({
	url:'https://reqres.in/api/users',
	method:'POST',
    data:{
    	name:"morpheus",
		job:"leader"
        }
     })
    .send()
    .then(function(response) { document.getElementById('response').textContent = response })
    .catch(function(failure) { alert ('Error') } )