form 表单内容序列化成一个字符串

html

html 复制代码
<form id="form1" action="http://localhost:8080/xxx" method="post">    
     <p >关键字1: <input type ="text" name="keyword1" /></p>    
     <p >关键字2: <input type ="text" name="keyword2" /></p>    
     <p >关键字3: <input type ="text" name="keyword3" /></p>    
     <input type ="submit" value="提交"/>    
</form> 

form 表单数据转 json 对象

复制代码
$( '#form1').serialize()

ajax 调用时提交表单数据

js 复制代码
$.ajax({  
     url : "http://localhost:8080/xxx",  
     type : "POST",  
     data : $( '#form1').serialize(),  
     success : function(data) {  
          $( '#serverResponse').html(data);  
     },  
     error : function(data) {  
          $( '#serverResponse').html(data.status + " : " + data.statusText + " : " + data.responseText);  
     }  
}); 
相关推荐
wno70418 小时前
node.js中使用jquery
前端·node.js·jquery
鶴哥只手遮天9 天前
jQuery 4.0 源码架构与工程实践-第 01 章 · 全景与工程结构:一个 20 岁库的自省
前端·javascript·jquery
鶴哥只手遮天10 天前
jQuery 4.0 源码架构与工程实践-第 10 章 尺寸、几何与显隐
前端·javascript·jquery
变与不变80611 天前
jQuery细节以及使用应用场景
前端·javascript·jquery
王大师王文峰16 天前
HTML 入门到进阶:语义化标签、表单与多媒体一篇打通【语义化布局、表单校验、video/audio、Canvas、无障碍与 SEO】
前端·css·node.js·html·css3·jquery·html5
变与不变80619 天前
jQuery 核心语法与 jQuery AJAX
前端·ajax·jquery
ycydynq19 天前
django用Bootstrap 模态框 在同一页面实现增删改查
django·bootstrap·jquery
传人once1 个月前
选择文件按钮样式如何美化
前端·html·css3·jquery·html5
传人once1 个月前
网页文字滚动效果如何做
前端·css·html·jquery·html5
传人once1 个月前
多图片上传预览功能如何写
前端·css·html·jquery·html5