0

我有一个 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>

哪个使用这个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 响应时显示“等待响应”消息。我该怎么做?

4

1 回答 1

1

您应该在此行之前显示它:

$.get('data.php', $(this).serialize(), function(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>
于 2013-06-23T01:12:54.213 回答