From 9148e9ce136a8580d2854d69029559bebd37f4b2 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Wed, 24 Aug 2016 13:19:59 -0400 Subject: [PATCH] notes for ajax, delete, post, update --- D3.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/D3.md b/D3.md index 7c904f0..a5ac1b1 100644 --- a/D3.md +++ b/D3.md @@ -60,6 +60,27 @@ d3.tsv('path', function(error, data){}); d3.xml('path', function(error, data){}); d3.html('path', function(error, data){}); d3.text('path', function(error, data){}); + +//make a post +d3.request('/runs') //make a request to the server + .header("Content-Type", "application/json") //tell the server we're sending JSON data + .post( + //must turn data object into string + JSON.stringify(runObject), + function(){ //callback + + } + ); + +//send delete +d3.request('/runs/'+d.id) + .header("Content-Type", "application/json") //we're sending data + .send('DELETE', function(){}); //send a DELETE request + +//send update +d3.request('/runs/'+d.id) + .header("Content-Type","application/json") //we're sending JSON + .send('PUT', JSON.stringify(d), function(){});//pass alterted 'd' object to API ``` ## Data binding