ajax提交form表单, 序列化表单的参数
//var a = $("#addfm").serialize(); //将表单的内容序列化成为一个字符串
var a = $("#addfm").serializeArray(); //将表单的内容序列化成为一个对象的数组, 每个对象以name:xxx,value:xxx的键值对存储
//这两个序列化的参数都是可以传递给后台的代码的
$.ajax({ type:"POST", url:"CmKhxxb/add.do", data:a, dataType:"json", success:function(data) { if(data.success) { $("#d_add").dialog("close"); $("#tab1").datagrid("reload"); $.messager.alert("提示","信息已经保存 ! "); } }, error: function (msg) { //ajax请求失败后触发的方法 var dataJson = eval("("+msg.responseText+")"); alert("错误信息: "+dataJson.reason+"\n状态码: "+msg.readyState); } });
时间戳和字符串之间的互相转换
js前台:
1、当前时间换时间戳
var timestamp = parseInt(new Date().getTime()/1000); // 当前时间戳
2、当前时间换日期字符串
var now = new Date(); var yy = now.getFullYear(); //年 var mm = now.getMonth() + 1; //月 var dd = now.getDate(); //日 var hh = now.getHours(); //时 var ii = now.getMinutes(); //分 var ss = now.getSeconds(); //秒 var clock = yy + "-"; if(mm < 10) clock += "0"; clock += mm + "-"; if(dd < 10) clock += "0"; clock += dd + " "; if(hh < 10) clock += "0"; clock += hh + ":"; if (ii < 10) clock += ‘0‘; clock += ii + ":"; if (ss < 10) clock += ‘0‘; clock += ss; document.write(clock); //获取当前日期
3、日期字符串转时间戳
var date = ‘2015-03-05 17:59:00.0‘; date = date.substring(0,19); date = date.replace(/-/g,‘/‘); var timestamp = new Date(date).getTime(); document.write(timestamp);
4、时间戳转日期字符串
var timestamp = ‘1425553097‘;
var d = new Date(timestamp * 1000); //根据时间戳生成的时间对象
var date = (d.getFullYear()) + "-" +
(d.getMonth() + 1) + "-" +
(d.getDate()) + " " +
(d.getHours()) + ":" +
(d.getMinutes()) + ":" +
(d.getSeconds());
document.write(date);