亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Javascript 詳解封裝from表單數(shù)據(jù)為json串進(jìn)行ajax提交

 更新時(shí)間:2017年03月29日 11:28:15   投稿:lqh  
這篇文章主要介紹了Javascript 詳解封裝from表單數(shù)據(jù)為json串進(jìn)行ajax提交的相關(guān)資料,需要的朋友可以參考下

摘要: js封裝from表單數(shù)據(jù)為json串進(jìn)行ajax提交

json封裝代碼

function getFormJson(frm) { //frm:form表單的id
    var o = {}; 
    var a = $("#"+frm).serializeArray(); 
    $.each(a, function() { 
      if (o[this.name] !== undefined) { 
        if (!o[this.name].push) { 
          o[this.name] = [ o[this.name] ]; 
        } 
        o[this.name].push(this.value || ''); 
      } else { 
        o[this.name] = this.value || ''; 
      } 
    }); 
    return o; 
  }

返回的數(shù)據(jù)格式為標(biāo)準(zhǔn)的json格式,ajax使用如下:

$.ajax({
  type: 'post',
  url: 'your url',
  data: getFormJson(frm),
  success: function(data) {
    // your code
  }
});


感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論