Jquery doesn't post for some reason
I wrote this small page and for some reason when I cilck on the submit nothing happens (checked on firebug, no submit is happening)
<head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$('form#login').submit(function() {
$.ajax({
type: 'POST',
url: 'http://my.site/login.php',
data: this.html(data),
开发者_运维技巧 success: success,
dataType: dataType
})
});
</script>
</head>
<body>
<form action="#" id="login">
<input type="textbox" id="UserName" value="user">
<input type="textbox" id="Password" value="password">
<input type="submit" value="submit">
</form>
</body>
You need to wrap your code to run on document.ready
, like this:
$(function() {
$('form#login').submit(function() {
$.ajax({
type: 'POST',
url: 'http://my.site/login.php',
data: this.html(data),
success: success,
dataType: dataType
})
});
});
Currently $('form#login')
is running before the form is present in the page, so it's not finding anything to hook that submit handler to, making it wait to run until document.ready
will fix this. As for why you don't see anything happening in firebug, your default form action is currently happening, submitting to #
, e.g. going nowhere...so no traffic for firebug to see.
精彩评论