Skip to content

Instantly share code, notes, and snippets.

@deepakkj
Created February 27, 2016 17:45
Show Gist options
  • Save deepakkj/6861a2502e17282d7566 to your computer and use it in GitHub Desktop.
Save deepakkj/6861a2502e17282d7566 to your computer and use it in GitHub Desktop.
Updating a item in JSON data using 'PUT' method
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Deepak Kumar Jain</title>
</head>
<body>
<h1>Updating a item in JSON data using 'PUT' method</h1>
<h4> - Using Jquery and REST API</h4>
<h2>Updating existing Friend's Detail</h2>
<small>Thanks to http://rest.learncode.academy/ for providing the RESTful API </small>
<script>
//using AJAX to add a update a collection/item to the JSON data from the given URL and call respective functions on success/error.
//URL used is only for learning/educational purposes. Cannot be used for production.
$.ajax({
type: "PUT",
data: {"name": "Mohan",
"age": "20"},
//here pass in respective "id" number in the URL to update an item
url: "rest.learncode.academy/api/deepak/friends/56d167d028e38101004a7e2d",
success: function(data){
console.log("Data updated/modified successfully");
},
error: function(data){
console.log("Error in updating/modifing data");
}
});
</script>
</body>
</html>
@deepakkj
Copy link
Author

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