Php ajax post等待消息

Php ajax post等待消息,php,ajax,Php,Ajax,我有一个html表单来提交一些信息: <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript" src="jquery-ui-1.7.2.custom.min.js"></script> <script type="text/javascript"> $(document).ready(fun

我有一个html表单来提交一些信息:

<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#form form').submit(function(){
            $.get('data.php', $(this).serialize(), function(data){
                $('#content').html(data);
            });             
            return false;
        });
    });
    </script>
</head>
<body>
<div id="form">
    <form>
         IP : <input type="text" name="urname"><br/>
        Port : <input type="text" name="urbirth"><br/>
        <input type="submit" name="submit" value="Submit">
    </form>
</div>
<div id="content">
</div>

$(文档).ready(函数(){
$('#表单')。提交(函数(){
$.get('data.php',$(this).serialize(),函数(data){
$('#content').html(数据);
});             
返回false;
});
});
IP:
端口:
它使用以下php:

<?php
error_reporting(0);
$name      = strtoupper($_REQUEST['urname']);
$birth     = strtoupper($_REQUEST['urbirth']);
$address   = "$name"; //Here you can specify the address you want to check ports
$port      = "80"; //Here you can specify the port you want to check from $address
$checkport = fsockopen($address, $port, $errnum, $errstr, 2); //The 2 is the time of ping in secs

//Here down you can put what to do when the port is closed
if (!$checkport) {
    echo "The port " . $port . " from " . $address . " seems to be closed."; //Only will echo that msg
} else {

    //And here, what you want to do when the port is open
    echo "The port " . $port . " from " . $address . " seems to be open."; //The msg echoed if port is open
}
?>


因为从服务器获得回复需要很长时间,所以我想在等待ajax响应的同时显示一条“等待响应”消息。我该怎么做?

您应该在这一行之前显示它:

$.get('data.php',$(this).serialize(),函数(data){

然后躲起来:

$('#content').html(数据)

您还可以使用$.ajaxStart和$.ajaxStop来处理所有AJAJ请求

$(document).ajaxStart(function() {
   $( "#loading" ).show();
 });
$(document).ajaxStop(function() {
      $( "#loading" ).hide();
});
使用这样的html

<div id="loading" style="display:none">waiting message<div>
等待消息

问题是什么?如果你告诉我们哪里出了问题/你遇到了什么困难,这会更容易。请看,当用户单击“提交”时,显示结果需要很长时间,因此我希望在这一次发出这样的消息:“Waint Please…”