關於ajax提交表單參數序列化和時間戳轉換


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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM