Ajax获取form表单提交数据
<!DOCTYPE html >
< html lang= “en” >
< head >
< meta charset= “UTF-8” >
< meta name= “viewport” content= “width=device-width, initial-scale=1.0” >
< meta http-equiv= “X-UA-Compatible” content= “ie=edge” >
< title >Document </ title >
< script src= “jquery-1.11.1.min.js” ></ script >
</ head >
< body >
< form id= “_form” method= “post” >
< div class= “fitem” >
< label > 房间: </ label >
< input name= “fangjian” style= “padding: 2px; width: 135px; border: 1px solid #A4BED4;” required />
</ div >
< div class= “fitem” >
< label > 建筑: </ label >
< input name= “jianzhu” class= “easyui-combobox” style= “padding: 2px; width: 141px; “ required />
</ div >
< div class= “fitem” >
< label > 部门: </ label >
< input name= “bumen” class= “easyui-combobox” style= “padding: 2px; width: 141px; “ required />
</ div >
</ form >
< script >
$( function(){
/*var str_data = $(‘#_form input’).map(function(){
return ($(this).attr(‘name’)+’=’+$(this).val());
}).get().join(‘&’);
alert(str_data);
*/
$. ajax({
var str_data = $(‘# _form input’). map( function(){
return ( $( this). attr( ‘name’)+ “=”+ $( this). val());
}).g et(). join(‘&’);
type: ‘post’,
url: ‘url’,
data:str_data,
success: function( msg){
// do something…
}
})
})
</ script >
</ body >
</ html >
还没有评论,来说两句吧...