Skip to content

Instantly share code, notes, and snippets.

@perminder-klair
Created October 30, 2013 10:57
Show Gist options
  • Save perminder-klair/7230724 to your computer and use it in GitHub Desktop.
Save perminder-klair/7230724 to your computer and use it in GitHub Desktop.
Post Json data to PHP using jquer ajax
var data = {"data1": "val1", "data2": "val2", "data3": "val3"};
var dataEncoded = JSON.stringify(data);
$.ajax({
type: "POST",
url: "post-data.php",
// The key needs to match your method's input parameter (case-sensitive).
data:{"data":dataEncoded},
dataType: "json",
success: function(data){
alert(data);
},
failure: function(errMsg) {
alert(errMsg);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment