Why am I getting 400 error (bad request) after creating an instance of RemoteDataStore???
var remoteDS = new App.RemoteDataStore(“http://coffeerun-v2-rest-api.herokuapp.com/api/coffeeorders”);
undefined
remoteDS.add(‘a@b.com’, {emailAddress: ‘a@b.com’, coffee: ‘espresso’});
undefined
I typed the above lines of code on the console and I keep getting the 400 error message. I have no idea where it went wrong… Can anyone help??
The following is my remotedatastore.js
(function(window) {
'use strict';
var App = window.App || {};
var $ = window.jQuery;
function RemoteDataStore(url) {
if (!url) {
throw new Error('No remote URL supplied.');
}
this.serverUrl = url;
}
RemoteDataStore.prototype.add = function (key, val) {
$.post(this.serverUrl, val, function (serverResponse) {
console.log(serverResponse);
}); //jQuery의 $.post 메소드를 사용
};
App.RemoteDataStore = RemoteDataStore;
window.App = App;
})(window);