Ajax獲取form表單提交資料
阿新 • • 發佈:2019-01-29
<!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()); }).get().join('&'); type:'post', url:'url', data:str_data, success:function(msg){ // do something... } }) }) </script> </body> </html>
<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()); }).get().join('&'); type:'post', url:'url', data:str_data, success:function(msg){ // do something... } }) }) </script> </body> </html>