javascript - How to insert a Date type variable in MySQL through JSON -



javascript - How to insert a Date type variable in MySQL through JSON -

i've table in database contains field type date. if seek insert date postman through api this:

{ "registerdate" : "2014-06-02" }

it works, seek javascript jquery taking value input in format yyyy-mm-dd or giving variable value "2014-06-02" inserts null value in 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){ });

where createuser is:

function createuser(url, type, user, success){ $.ajax({ url:url, type: 'post', crossdomain : true, contenttype : type, info : user }) .done(function (data, status, jqxhr) { success(user); }) .fail(function (jqxhr, textstatus) { console.log(textstatus); }); }

where problem if in postman works javascript doesn't?

as suggestion (a comment big), may want convert date miliseconds using parse method:

date.parse('2014-06-02');

send json:

{'registerdate' : '1401685200'}

and parse in mysql using from_unixtime function.

from_unixtime(1401685200)

or better, can store date integer value on database , convert date whenever need it; since storing string may cause issues encoding.

javascript mysql json api

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -