开发者

Please help with ajax script + jquery [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I don't know anything about JavaScript. I need the following:

  1. Message "Please wait" appears in #note when user submits form.
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜