1

Fixing up parsing

This commit is contained in:
Alex Yatskov 2015-03-24 11:58:00 +09:00
parent cef05a15a4
commit dbafb279b0
2 changed files with 9 additions and 10 deletions

View File

@ -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
}

View File

@ -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() {