https://blog.csdn.net/n447194252/article/details/77839594
<script type="application/javascript"> //发送表单ajax请求 $(':submit').on('click',function(){ $.ajax({ url:"buy", type:"POST", data:JSON.stringify($('form').serializeObject()), contentType:"application/json", //缺失会出现URL编码,无法转成json对象 success:function(){ alert("成功"); } }); }); /** * 自动将form表单封装成json对象 */ $.fn.serializeObject = function() { var o = {}; var a = this.serializeArray(); $.each(a, function() { if (o[this.name]) { 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; }; </script>