I'm working on a site that keeps track of a to-do list and pulls it from a server. There are two sample ajax calls below. The tasks GET call works fine, however the add POST does not. For some reason, it gives me a 403 forbidden error and as a result, doesn't execute the code.
I was looking at 403 Forbidden error when making an ajax Post request in Django framework and i read the link posted by @yohn, but I'm not understanding how to implement this solution.
var tasker = (function() {
return {
tasks : function( ownerId, cb ) {
$.ajax({
url: "http://138.49.184.143:3000/tasker/api/"+ownerId+"?key=f725ebbc9c",
type: 'GET',
success: function(task) {
if(task){
var list = []
for(var a=0; a<task.length; a++){
var newTask = {
onwerId: task[a].ownderId,
desc: task[a].desc,
due: new Date(task[a].due),
color: task[a].color,
complete: task[a].complete,
id: task[a].id
};
list.push(newTask);
}
cb(list , null);
}
else{ cb(null, 'error retreiving your tasks');}
},
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem! " + errorThrown );
},
});
},
add : function( ownerId, task, cb ) {
$.ajax({
url: "http://138.49.184.143:3000/tasker/api/"+ownerId+"?key=f725ebbc9c",
type: 'POST',
success: function(task) {
var d = new Date(task.due);
if(task){
var newTask = {
onwerId: task.ownderId,
desc: task.desc,
due: d,
color: task.color,
complete: task.complete,
id: task.id
};
cb(newTask , null);
}
else{cb(null, 'error adding your task');}
},
error: function( xhr, status, errorThrown ) {
alert( "Sorry, there was a problem! " + errorThrown );
},
});
},
}
})();