Hello;
I've written an API using Django-rest. Whenever I try to put a row from JS grid to the server I get a HTTP-400-Error. When I look a bit deeper my errors are
{'destination_ip': ['This field is required.'], 'source_ip': ['This field is required.'], 'protocol': ['This field is required.']}
[02/Mar/2017 17:28:18] "PUT /rules/BCAAPI/737/Production/2240/ HTTP/1.1" 400 125
This would seem to indicate that the PUT request is not passing the fields destination_ip, source_ip and protocol. Does anyone have any insight into this problem after observing the code below? The server is behaving as expected but jsGrid does not appear to be.
$(function() {
$("#jsGrid").jsGrid({
height:"auto",
width: "100%",
editing: true,
inserting: true,
sorting: false,
paging: false,
autoload: true,
controller: {
loadData: function(item) {
var d = $.Deferred();
$.ajax({
type: "GET",
url: "http://localhost:8000/rules/BCAAPI/{{ plane_model }}/{{ table_type }}/",
}).done(function(response) {
console.log("done");
d.resolve($.map(response, function(item) {
return $.extend(item.fields, { id: item.id,
model: item.model,
table: item.table,
src_ip: item.source_ip,
dst_ip: item.destination_ip,
proto: item.protocol,
src_lo: item.source_port_lo,
src_hi: item.source_port_hi,
dst_lo: item.destination_port_lo,
dst_hi: item.destination_port_hi,
Pcapfile: item.Pcapfile,
origin: item.origin,
created: item.created,
last_edited: item.last_edited,
owner: item.owner,
tailnumber: item.tailnumber,
feature: item.feature,
comments: item.comments
});
}));
}).fail(function() {
console.log("fail");
d.reject();
});
return d.promise();
},
insertItem: function(item) {
return $.ajax({
type: "POST",
url: "http://localhost:8000/rules/BCAAPI/{{ table_type }}/",
data: $.extend(item.fields, { id: item.id,
model: item.model,
table: item.table,
src_ip: item.source_ip,
dst_ip: item.destination_ip,
proto: item.protocol,
src_lo: item.source_port_lo,
src_hi: item.source_port_hi,
dst_lo: item.destination_port_lo,
dst_hi: item.destination_port_hi,
Pcapfile: item.Pcapfile,
origin: item.origin,
created: item.created,
last_edited: item.last_edited,
owner: item.owner,
tailnumber: item.tailnumber,
feature: item.feature,
comments: item.comments})
});
},
updateItem: function(item) {
return $.ajax({
type: "PUT",
url: "http://localhost:8000/rules/BCAAPI/{{ table_type}}/" + item.id + "/",
data: $.extend(item.fields, { id: item.id,
model: item.model,
table: item.table,
src_ip: item.source_ip,
dst_ip: item.destination_ip,
proto: item.protocol,
src_lo: item.source_port_lo,
src_hi: item.source_port_hi,
dst_lo: item.destination_port_lo,
dst_hi: item.destination_port_hi,
Pcapfile: item.Pcapfile,
origin: item.origin,
created: item.created,
last_edited: item.last_edited,
owner: item.owner,
tailnumber: item.tailnumber,
feature: item.feature,
comments: item.comments})
});
},
deleteItem: function(item) {
return $.ajax({
type: "DELETE",
url: "http://localhost:8000/rules/BCAAPI/{{ table_type }}/" + item.id + "/",
data: $.extend(item.fields, { id: item.id,
model: item.model,
table: item.table,
src_ip: item.source_ip,
dst_ip: item.destination_ip,
proto: item.protocol,
src_lo: item.source_port_lo,
src_hi: item.source_port_hi,
dst_lo: item.destination_port_lo,
dst_hi: item.destination_port_hi,
Pcapfile: item.Pcapfile,
origin: item.origin,
created: item.created,
last_edited: item.last_edited,
owner: item.owner,
feature: item.feature,
comments: item.comments})
});
}
},
fields: [
{ name: "src_ip", type: "text", width:250},
{ name: "dst_ip", type: "text", width:250},
{ name: "proto", type: "text",width:100},
{ name: "src_lo", type: "number", width:150},
{ name: "src_hi", type: "number", width:150},
{ name: "dst_lo", type: "number",width:150},
{ name: "dst_hi", type: "number",width:150},
{ name: "Pcapfile", type: "text", width:300},
{ name: "origin", type: "text",width:100},
{ name: "created", type: "textarea", width:400},
{ name: "last_edited", type: "textarea",width:400},
{ name: "owner", type: "text",width:100},
{ name: "feature", type: "text",width:100},
{ name: "comments", type: "textarea",width:225},
{ type: "control"}
]
});
});
</script>
Your api seems to require source_id but you are passing src_ip.
Regardless, this is not a problem with JSGrid.
Thank you;
You are right. I did find that typo soon after posting.
Sure thing! Glad you figured it out :)