阅读背景:

Jq form表单提交验证与响应简单示例

来源:互联网 
 
 
<!DOCTYPE html>
<html>

	<head>
		<title>表单提交验证与响应</title>
	</head>

	<body>
		<form method="post" onsubmit="return verification()">
			<input name="name" id='name' type='text' placeholder='姓名(必填)' />
			<input name="content" id='content' type='text' placeholder='内容(必填)' />
			<input type='submit' value='提交' />
		</form>

		<script>
			function verification() {
				if($('#reqName').val() == '') {
					alert('姓名不能为空!');
					return false;
				}
				if($('#reqContent').val() == '') {
					alert('内容不能为空!');
					return false;
				}
				$.ajax({
					url: "{:create_addon_url('deal')}",
					type: 'post',
					dataType: 'json',
					data: {
						'name': $('#reqName').val(),
						'email': $('#reqEmail').val(),
						'contact': $('#reqPhone').val(),
						'content': $('#reqContent').val()
					},
					success: function(data) {
						alert("提交成功," + data.info);
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						alert("发生错误," + textStatus);
					}
				});
				return true;
			}
		</script>
	</body>

</html><!DOCTYPE html>
<html>

	<head>
		<title>表单提



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: