Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created April 5, 2013 15:57
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 joyrexus/5320443 to your computer and use it in GitHub Desktop.
Save joyrexus/5320443 to your computer and use it in GitHub Desktop.
XHR posting example.

XHR

See also:

Vanilla

req = new XMLHttpRequest()
req.open "POST", "path/to/api", on
req.onreadystatechange = -> 
  return if req.readyState isnt 4 or req.status isnt 200
  alert "The response was \"#{req.responseText}\""
req.send "banana=yellow"

JQ

$.ajax
  type: 'POST'
  url: "path/to/api"
  data: "banana=yellow"
  success: (data) -> alert "The response was \"#{req.responseText}\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment