In my database, there is a table with a Date field. I noticed that when I try to insert a date using Postman through the API like this:
{
"registerDate" : "2014-06-02"
}
It successfully inserts the date. However, when I attempt to do the same using JavaScript and jQuery by retrieving the value from an input in the format YYYY-MM-DD or even directly assigning the value "2014-06-02" to the variable, it results in inserting a NULL value in the database.
var user = new Object();
user.registerDate = $('#register_date').val();
createUser(url, type, JSON.stringify(user), function(user){
});
or
var user = new Object();
user.registerDate = "2014-06-02";
createUser(url, type, JSON.stringify(user), function(user){
});
The createUser function used is as follows:
function createUser(url, type, user, success){
$.ajax({
url:url,
type: 'POST',
crossDomain : true,
contentType : type,
data : user
})
.done(function (data, status, jqxhr) {
success(user);
})
.fail(function (jqXHR, textStatus) {
console.log(textStatus);
});
}
I am puzzled as to why it works in postman but not through JavaScript?