src/public/resources/js/main.js
//  Sending to-do item to API
Sending to-do item to API
Sending to - do item to API
function sendTaskToAPI(item, callback) {
  var req = new XMLHttpRequest();
  req.open('POST', '/tasks/add');
  req.setRequestHeader('Content-Type', 'application/json');
  req.send(JSON.stringify({ item: item }));
  req.addEventListener('load', () => {
    var results = JSON.parse(req.responseText);
    if (results.error) return console.log(results.error);
    if (callback) callback(results);
  });
  req.addEventListener('error', (e) => {
    console.log('Shit, something bad happened.');
    console.log(e);
  });
}
function sendTaskToAPI ( item , callback ) { var req = new XMLHttpRequest ( ) ; req . open ( 'POST' , '/tasks/add' ) ; req . setRequestHeader ( 'Content-Type' , 'application/json' ) ; req . send ( JSON . stringify ( { item : item } ) ) ; req . addEventListener ( 'load' , ( ) => { var results = JSON . parse ( req . responseText ) ; if ( results . error ) return console . log ( results . error ) ; if ( callback ) callback ( results ) ; } ) ; req . addEventListener ( 'error' , ( e ) => { console . log ( 'Shit, something bad happened.' ) ; console . log ( e ) ; } ) ; }
Sending to-do item to API
Sending to - do item to API