Skip to content

Instantly share code, notes, and snippets.

@jjjjcccjjf
Last active March 7, 2018 03:22
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 jjjjcccjjf/02b3d3d1e719a4b083478ffdf51b2ca9 to your computer and use it in GitHub Desktop.
Save jjjjcccjjf/02b3d3d1e719a4b083478ffdf51b2ca9 to your computer and use it in GitHub Desktop.
Ajax sample code
// GET JSON BLOCK

$.getJSON('http://localhost/api/members', function(result){ 

});
// GET JSON BLOCK
// AJAX BLOCK
$("#the_id_of_the_form").submit(function(e){

  var form_data = new FormData($(this)[0]);

  $.ajax({
    url: 'http://localhost/admin/ajax.php',
    type: 'POST',
    data: form_data,
    success: function (result, textStatus, xhr) {
    if(xhr.status == 200){
      // do something
    }else{
      alert('Enzo is awesome. But your code is hmm... How should I put it?');
    },
    error: function(e){
      console.log(e);
    },
    cache: false,
  contentType: false,
  processData: false
  });
  
e.preventDefault();
});

// AJAX BLOCK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment