[英]Html form is not working with Php, Ajax request
您好,以下是我要使用Ajax验证的html表单。 这样浏览器就不会加载页面。 如果用户输入名字,则应在html表单上方显示名字。 但是它没有显示...
HTML形式:
<form id="validation"/>
<table width="500" border="0" cellspacing="10" cellpadding="0">
<tr>
<td>First Name</td>
<td><input type="text" name="fname" value="<?php if(isset($_POST['fname'])) echo $_POST['fname']; ?>" class="tr" placeholder="First Name"/></td>
</tr>
<tr>
<td></td>
<td><input type="reset" name="reset" value="Clear" class="submit"/> <input type="submit" name="Submit" id="submit" value="Registration" class="submit"/></td>
</tr>
</table>
</form>
<script>
$('#validation').submit(function(event) {
event.preventDefault();
$.ajax({
type: 'POST',
url: 'regProcess.php',
data: $(this).serialize(),
dataType: 'json',
success: function (data) {
}
});
});
</script>
邮递区号:
<?php
if(isset($_POST['Submit']) && $_POST['Submit'] == "Registration"){
$fname = $_POST['fname'];
echo $fname;
}
?>
在代码底部附近,您有以下内容:
success: function (data) {
}
那是你的问题。 您对返回的“数据”不做任何事情-您需要使用javascript或jquery将其插入到DOM中的某个位置。 编辑:更新
要使用jquery将数据插入dom,请执行以下操作:
success: function (data) {
$("#id of the element where you want the data").innerHTML+=data
}
这会将从AJAX检索到的“数据”附加到具有特定ID的元素中。 我相信您可以在$(“ HERE”)内使用任何CSS选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.