I've been facing a problem while trying to send a JSON object to the server using AJAX calls. I keep getting a 404 Bad Request error. The issue seems to be related to the fact that I have a form where I convert the form data into a JSON object, but the table in my database has an auto-incremented primary key (id) that is not included in the form fields. Here is the relevant code snippet from my controller:
var Bus= angular.module('Bus',[]);
Bus.controller('BusController',function($scope,$http) {
$scope.business = {}
$scope.submitMyForm=function(){
console.log($scope.business);
var q=JSON.stringify($scope.business)
console.log(q)
$
.ajax({
type : 'POST',
url : " some url",
data :JSON.stringify($scope.business),
success: function(){
alert('success');
},
error : function(e) {
console.log(e);
alert('oops!!');
},
dataType : "json",
contentType : "application/json"
});
};
});
How can I resolve this issue? Any help or suggestions would be greatly appreciated. Thanks in advance!