Skip to content

Instantly share code, notes, and snippets.

@saylerb
Last active July 26, 2016 15:59
Show Gist options
  • Select an option

  • Save saylerb/2bc14a8368923541fbadecab95bf9397 to your computer and use it in GitHub Desktop.

Select an option

Save saylerb/2bc14a8368923541fbadecab95bf9397 to your computer and use it in GitHub Desktop.

Why use AJAX?

  • AJAX = Asynchronous JavaScript + XML (although JSON is used more these days)
  • No refresh
  • Less bandwidth
  • Split the work between the client and server
    • Offload some of the work to the user's computer

Asynchronous

 $.ajax({
    url: "https://turing-birdie.herokuapp.com/api/v1/posts",
    method: "GET",
    dataType: "JSON",
    success: function(posts){ // <- the 'posts' here is kind of like a block parameter in ruby |posts|

    }

  })
 $.ajax({
    url: "https://turing-birdie.herokuapp.com/api/v1/posts.json",
    method: "GET",
    dataType: "JSON",
    success: function(posts){
      console.table(posts)
    }

  })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment