I am trying to teach myself jquery, (not so successfully so far) why doesn’t the div with id fill get updated when i click submit?
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input#go").click(function(){
$("div#fill").load('test1.txt');
});
});
</script>
</head>
<body>
<form name="login">
<label><strong>Administrative Login </strong></label>
<p>Username:</p>
<input name="username" type="text" id="username" />
<p>Password</p>
<input name="password" type="password" id="password" />
<br>
<input type="Submit" id="go">
<div id="fill"></div>
You need to cancel the default action of the submit button by returning false in the click handler:
By returning false, the form is not being submitted normally, the browser stays on the same page and the AJAX call that you are performing to fetch the
text.txtfile from your server has enough time to execute.As an alternative I would recommend you subscribing to the submit event of the form instead of the click event of the submit button:
This will ensures that the AJAX call will be executed everytime the form is submitted, not only if the submit button is clicked. But of course that will depend on your requirements.