Skip to content

Instantly share code, notes, and snippets.

@leesmith
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leesmith/5ce2ddb86051699f79ca to your computer and use it in GitHub Desktop.
Save leesmith/5ce2ddb86051699f79ca to your computer and use it in GitHub Desktop.
jQuery event delegation
$(document).ready ->
$(document)
.on('ajax:before', ".single-line-qualification", (e) ->
debugger
# do validation and return false to cancel ajax
if e.target[1].value.trim() == ''
e.target[1].value = ''
alert 'You must enter a name!'
return false
)
.on("ajax:success", ".single-line-qualification", (e, data, status, xhr) ->
$('#qualifications').append xhr.responseText
e.target.remove()
# append success message
)
.on("ajax:error", ".single-line-qualification", (e, xhr, status, error) ->
# append error message
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment