Skip to content

Instantly share code, notes, and snippets.

@tayler
Last active December 12, 2015 02:38
Show Gist options
  • Save tayler/4699834 to your computer and use it in GitHub Desktop.
Save tayler/4699834 to your computer and use it in GitHub Desktop.
standard ajax post with jQuery
// http://www.jqapi.com/#p=jQuery.ajax
var email = $("input#email").val();
var user = $("input#user").val();
var pass = $("input#pass").val();
var dataToSend = {
email: email,
username: user,
password: pass
}
$.ajax({
url: 'http://location.of.the/file/that/accepts/this/data.php',
data: dataToSend, // what you want to send
type: 'POST', // how you want to send it; POST is for sending data to the server, GET is for GETting. (there are others)
success: function(dataRecievedFromServer) {
// you've received a response from the server
$("div#successMsg").html("Your account was created");
// do something with dataReceivedFromServer, if necessary
},
error: function(error) {
console.log(error);
// or tell user the submission was unsuccessful
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment