user2507818
user2507818

Reputation: 3047

issue with submit in jquery

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>

Question:

For return false;, from I know, it will stop the submit action, so I think when I click submit button, it will load the data first, then stop submit action. But after I remove return false;, it did not load the data any more, why?

Upvotes: 0

Views: 38

Answers (1)

U.P
U.P

Reputation: 7442

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.

Upvotes: 1

Related Questions