weixin_33694172 2014-09-20 15:17 采纳率: 0%
浏览 12

AJAX jQuery返回消息?

I have this AJAX call

$(function() {
    $("button#submit").click(function(){
               $.ajax({
                   type: "POST",
            url: "process.php",
            data: $("form.contact").serialize(),
                success: function(msg){
                    $(".alert-success").toggle();
                    $("#form-content").modal("hide");    
                },
            error: function(){
                $(".alert-error").toggle();
                }
                  });
    });
});

The problem is that in process.php i only have

echo "OK";

In console i see resposne but not on page, what can be problem?

  • 写回答

1条回答 默认 最新

  • weixin_33694172 2014-09-20 15:19
    关注

    You get msg as result of ajax call but you don't use it anywhere. You can use it inside success for example:

    $(function() {
        $("button#submit").click(function(){
                   $.ajax({
                       type: "POST",
                url: "process.php",
                data: $("form.contact").serialize(),
                    success: function(msg){
                        $(".alert-success").toggle();
                        $("#form-content").modal("hide");
                        //console.log(msg); to get the result in console for example
                    },
                error: function(){
                    $(".alert-error").toggle();
                    }
                      });
        });
    });
    
    评论

报告相同问题?