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

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 调用时提交表单数据

$.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);  
     }  
}); 

你可能感兴趣的:(jquery,jquery)