From dbafb279b06c7cc58538b99c682676e2c34317c7 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 24 Mar 2015 11:58:00 +0900 Subject: [PATCH] Fixing up parsing --- server.go | 5 ++--- static/scripts/profile.js | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/server.go b/server.go index 542a299..c0cc47d 100644 --- a/server.go +++ b/server.go @@ -91,10 +91,9 @@ func removeCategory(rw http.ResponseWriter, req *http.Request) { Id int `json:"id"` } - decoder := json.NewDecoder(req.Body) - var request Request - if err := decoder.Decode(&request); err != nil { + if err := json.NewDecoder(req.Body).Decode(&request); err != nil { + log.Print(err) http.Error(rw, err.Error(), http.StatusInternalServerError) return } diff --git a/static/scripts/profile.js b/static/scripts/profile.js index 8e2c75b..cf1d8ea 100644 --- a/static/scripts/profile.js +++ b/static/scripts/profile.js @@ -35,7 +35,7 @@ } function addCategory(description) { - $.getJSON('/learn', {description: description}, function(results) { + $.post('/learn', JSON.stringify({description: description}), function(results) { if (!results.success) { return; } @@ -47,17 +47,17 @@ }]; displayCategories(categories); - }); + }, 'json'); } function removeCategory(id) { - $.getJSON('/forget', {id: id}, function(results) { + $.post('/forget', JSON.stringify({id: id}), function(results) { if (results.success) { $('tr.category_' + id).fadeOut(function() { $(this).remove(); }); } - }); + }, 'json'); } function displayCategories(categories) { @@ -70,7 +70,7 @@ $('#categories button').unbind().click(function() { if (confirm('Are you sure you want to delete this category?')) { - removeCategory($(this).attr('data-categoryId')); + removeCategory(parseInt($(this).attr('data-categoryId'))); } }); } @@ -80,7 +80,7 @@ } function refreshCategories() { - $.getJSON('/categories', function(results) { + $.get('/categories', function(results) { var categories = []; _.each(results, function(result) { @@ -93,7 +93,7 @@ clearCategories(); displayCategories(categories); - }); + }, 'json'); } function submitCategory() {