Ajax获取form表单提交数据

本是古典 何须时尚 2022-06-16 12:27 480阅读 0赞

<!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 >

发表评论

表情:
评论列表 (有 0 条评论,480人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Ajax提交Form

    1. 背景 在java后台开发中,经常要从前端向后台提交表单数据。利用Ajax进行Form表单提交,是很常用的方法。本文主要讲解Ajax提交表单的基本应用。 2. Ajax