Ajax 提交整个页面的数据

HTML

....
<form id='f1'>
     <input type = 'text' name='u1'/>
     <input type = 'text' name='us1'/>
     <input type = 'text' name='uw1'/>
     <input type = 'text' name='ue1'/>
     <input type = 'text' name='ur1'/>
</form> ...

ajax 提交, 后台会生成一个字典,key 是name, value 是对应的值

$.ajax({
  url:....
  data: $("#f1").seralize()
})

如果HTML中存在select 标签,并且设置了mulitiple属性,在ajax提交的时候要加一个属性 traditional:true

$.ajax({
  url:....
  data: $("#f1").seralize(),
   traditional: true
})

猜你喜欢

转载自www.cnblogs.com/gaizhongfeng/p/10410747.html