用ajax的POST方法提交表单数据,但后台一直调用的GET路由方法
发布于 8 年前 作者 baidiao 5418 次浏览 来自 问答
<form id="form1" >
					<div class="aui-input-row">
						<span class="aui-input-addon">姓&nbsp;&nbsp;名</span>
						<input type="text" class="aui-input" id="name" name="name" placeholder="姓名"/>
					</div>
					<div class="aui-input-row">
						<span class="aui-input-addon">性&nbsp;&nbsp;别</span>
						<input class="aui-radio" type="radio" id="sex" name="sex" checked><div class="aui-radio-name">男</div>
						<input class="aui-radio" type="radio" name="sex"><div class="aui-radio-name">女</div>
					</div>
					<div class="aui-input-row">
						<span class="aui-input-addon">电&nbsp;&nbsp;话</span>
						<input type="text" class="aui-input" id="tel" name="tel" placeholder="电话"/>
					</div>
					<div class="aui-input-row">
						<span class="aui-input-addon">地&nbsp;&nbsp;址</span>
						<input type="text" class="aui-input" id="add" name="add" placeholder="地址"/>
					</div>
					<div class="aui-input-row">
						<span class="aui-input-addon">电子邮件</span>
						<input type="text" class="aui-input" id="email" name="email" placeholder="电子邮件"/>
					</div>
					<div class="aui-input-row">
						<span class="aui-input-addon">咨询主题</span>
						<input type="text" class="aui-input" id="topic" name="topic" placeholder="咨询主题"/>
					</div>
					<div class="aui-input-row">
						<span class="aui-input-addon">咨询内容</span>
						<textarea class="aui-input" rows="3" id="content" name="content" placeholder="咨询内容"></textarea>
					</div>
					<div class="aui-btn-row">
						<input class="aui-btn aui-btn-success" type="submit" id="btn_sub" name="btn_sub" value="提交问题"/>						
						<div class="aui-btn aui-btn-success" onclick="history.go(-1)">取消提问</div>					
					</div>
				</form>
			</div>
		</div>
	</section>

	<script type="text/javascript">
		$(function(){ 
			//$("#btn_sub").click(function(){ 
			$("#form1").submit(function(){
				var name = $("#name").val();
				var sex = $("#sex").val();
				var tel = $("#tel").val();
				var add = $("#add").val();
				var email = $("#email").val();
				var topic = $("#topic").val();
				var content = $("#content").val();
				
				$.ajax({ 
					url: '/sub_zxzx',
					type: 'post',
					dataType: 'json',
					data: {"name":name,
							"sex":sex,
							"tel":tel,
							"add":add,
							"emial":email,
							"topic":topic,
							"content":content},
					success: function(data,status){ 
						if(status == 'success'){ 
							alert('success!');
						}
					},
					error: function(data,err){ 
							alert('error!');
					}
				}); 
			
			});
		});
		
	</script>

#鼓捣了半天了,咋整也不好使,麻烦哪位给看看

2 回复

$("#form1").submit(function(event){ event.preventDefault(); ...... } 加个

event.preventDefault();

试试

你用POST提交却用GET获取,咋整能好使 ?

回到顶部