Skip to content

Instantly share code, notes, and snippets.

@deepakkj
Created February 27, 2016 17:45
Show Gist options
  • Select an option

  • Save deepakkj/6861a2502e17282d7566 to your computer and use it in GitHub Desktop.

Select an option

Save deepakkj/6861a2502e17282d7566 to your computer and use it in GitHub Desktop.

Revisions

  1. deepakkj created this gist Feb 27, 2016.
    39 changes: 39 additions & 0 deletions updata_jsonData_REST.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    <!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>