如何在结果显示的同一Div中显示加载消息

时间:2014-05-22 10:11:48

标签: php jquery ajax loading

我有这样的请求在表单提交后发送邮件。

post_data = {'userName':name, 'userEmail':email, 'userMessage':message};

        //Ajax post data to server
        $.post('contact_me.php', post_data, function(response){  

            //load json data from server and output message     
            if(response.type == 'error')
            {
                output = '<p style="color:red;" class="help-block">Oh no!! Error occured</p>';
            }else{
                output = '<p style="color:green;" class="help-block">'+response.text+'</p>';

                //reset values in all input fields
                $('#contact_form input').val(''); 
                $('#contact_form textarea').val(''); 
            }

            $("#result").hide().html(output).slideDown();
        }, 'json');

收到回复后,我会在此div中显示消息

<div id="result" class="col-md-8"></div>

现在我需要在处理ajax请求时在同一个div中显示加载消息。怎么做?我见过很多答案但与此类查询没什么关系

1 个答案:

答案 0 :(得分:0)

像这样:

$("#result").append("Loading Data...");

 //Ajax post data to server

        $.post('contact_me.php', post_data, function(response){ 

         $("#result").html(response);

         }