Please help with ajax script + jquery [closed]
I don't know anything about JavaScript. I need the following:
- Message "Please wait" appears in
#note
when user submits form. - After form has been processed this message disappears and then in
#note
fades in "result" or "Error".
<script type="text/javascript">
$(document).ready(function() {
$("#sendmessage").submit(function() {
$("#note").fadeIn(1000).html('PLease wait...');
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "/send.php",
data: str,
success: function(msg) {
$("#note开发者_如何学运维").ajaxComplete(function(event, request, settings) {
if (msg == "NOTOK") {
result = 'Error';
$(this).html(result);
} else {
$("#fields").hide();
result = msg;
$(this).html(result);
}
});
}
});
return false;
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#sendmessage").submit(function() {
$("#note").fadeIn(1000).html('PLease wait...');
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "/send.php",
data: str,
success: function(data) {
$("#note").html(data);
$("#fields").hide();
},
error: function() {
$("#note").html('Error');
}
});
return false;
});
});
Just add
$(this).fadeIn();
at .ajaxComplete
. You've implemented the rest aready, haven't you?
Please remove the ajaxComplete part. It serves a different purpose: http://api.jquery.com/ajaxComplete/
Elaboration
If jQuery enters success
, the ajax call has already completed. Adding a handler to #note
at that point has no effect whatsoever.
精彩评论