data.php:
<?php
$name = strtoupper($_REQUEST['name']);
if(isset($name)){
$html = "<p>Your name: <b>".$name."</b></p>";
print($html);
}
?>
index.html:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#form form').submit(function(){
$('#content').load('data.php', { 'name': $('input[name="urname"]').val()});
return false;
});
});
</script>
</head>
<body>
<div id="form">
<form>
Name : <input type="text" name="urname"><br />
<input type="submit" name="submit" value="Submit">
</form>
</div>
<div id="content">
</div>
</body>
</html>
问题: 对于return false;,据我所知,它可以用于停止提交动作,所以当我单击Submit按钮时,它理应首先加载数据、然后停止提交动作。但是在删除return false;之后,它却不再加载数据了......为什么?
When you remove the return false;
the page refreshes because it then submits the form. That is why you cannot see the effect of load function.