<div id="content" style="display:none">数据正在载入,请稍候...<div>
<a href="#" onClick="loadingMain();">主页</a>//点这个链接就显示content
<script>
$(document).ready(function() {
 $("#content").ajaxStart(function(){
   $(this).show();
 }); 
});
</script>//是不是说我在任何时候使用ajax都调用ajaxstart?
<script>function loadingMain(){
$.get("test1.asp"); 
}</script>我这样写对吗??要不帮忙改改

解决方案 »

  1.   

    你这个应该使用什么类库的吧?比如说jquery或者说其他的什么类库的吧?
      

  2.   

    Register a handler to be called when the first Ajax request begins. This is an Ajax Event
    这是APIajaxStart和ajaxStop主要是在页面触发ajax时,呼叫其他function或程式码做处理。这是例子:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>jQuery ajaxStart() Example</title>
        <script type="text/javascript"src="jquery.js"></script>
        <script type="text/javascript">
        //<![CDATA[
        
            $(document).ready(function () {
                $("div#divStatus").ajaxStart(function () {
                    $(this).html("Contacting the server");
                }).ajaxStop(function () {
                    $(this).html("Response received.");
                });
            });                
            
            //function to get customer information
            function requestCustomerInfo() {
            
                //get the ID
                var sId = $("input#txtCustomerId").val();            //send the request
                $("div#divCustomerInfo").load("GetCustomerData.aspx?id=" + sId);            
            }        //]]>
        </script>
    </head>
    <body>
        <p>Enter customer ID number to retrieve information:</p>
        <p>Customer ID: <input type="text" id="txtCustomerId" value="" /></p>
        <p><input type="button" value="Get Customer Info" onclick="requestCustomerInfo()" /></p>
        <div id="divStatus" style="color: blue"></div>
        <div id="divCustomerInfo"></div>    
    </body>
    </html>
      

  3.   

    function loadingMain(){
    $.get("test1.asp");  
    }我想不让这个ajax调用全局的ajaxStart说加个global:false 是这样写吗?
    function loadingMain(){
    $.get("test1.asp",{global:false });  
    }
      

  4.   

    可以吗?在get里取消全局的ajaxstart?还是必须写成$.ajax({
        url: 'test1.asp',
        type: 'GET',
       global:false ,
     ....
      

  5.   

    .ajaxStart()和.ajaxStop()方法就是这些观察员函数的两个列子,可以把他们添加给任何jQuery对象。当最后一次活动请求终止时,则会执行通过.ajaxStop()注册的回调函数.所有观察员都是全局的,因此无论创建他们的代码位于何处,当ajax通信发生时都需要调用它们。