Skip to content

Instantly share code, notes, and snippets.

@efleming969
Created March 21, 2018 18:27
Show Gist options
  • Save efleming969/85770071f63f08b6af3c6c89b2e5e8ba to your computer and use it in GitHub Desktop.
Save efleming969/85770071f63f08b6af3c6c89b2e5e8ba to your computer and use it in GitHub Desktop.
var index = ( function () {
var exports = {}
exports.start = function() {
console.log( "Main::start" )
$( "#frm" ).on( "submit", function( event ) {
var newGreeting = {
id: utils.generateId(),
text: $( "#text" ).val()
}
var jsonData = JSON.stringify( newGreeting )
$.post( "/api/greetings", jsonData, function( data ) {
$( "#greetings" ).append( `<li>${newGreeting.text}</li>` )
}, "json" )
event.preventDefault()
} )
$.get( "/api/greetings", function( greetings ) {
$( "#greetings" ).html( greetings.map( function( greeting ) {
return `<li>${ greeting.text }</li>`
} ) )
}, "json" )
}
exports.buildGreeting = function() {
return "hello, world!"
}
return exports
} )()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment