Javascript ajax进度条图像隐藏和显示

Javascript ajax进度条图像隐藏和显示,javascript,jquery,ajax,Javascript,Jquery,Ajax,当我点击一个按钮,我想显示一个图像,并在完成图像隐藏。我的剧本怎么了 <script type="text/javascript"> $(element).click(function(){ $(".navigation-jpg").show(); $.ajax({ success: function(){ $(".navigation-jpg").hide(); } }); }); </scri

当我点击一个按钮,我想显示一个图像,并在完成图像隐藏。我的剧本怎么了

<script type="text/javascript">

$(element).click(function(){
    $(".navigation-jpg").show();
    $.ajax({
        success: function(){
            $(".navigation-jpg").hide();
        }
    });
});
</script>

<div class="ajax-content">

    <img src="navigation.jpg" alt="Loading" class="loading-gif" style="display:none"/>
    <div class="ajax-response">
    </div>
            <asp:Button ID="Button1" runat="server" Text="Button" />

       </div>

$(元素)。单击(函数(){
$(“.navigation jpg”).show();
$.ajax({
成功:函数(){
$(“.navigation jpg”).hide();
}
});
});

您在javascript中使用类
导航jpg
,但在HTML中使用类
加载gif
。保持一致,你就是好人

更新:其他回答者也发现在事件处理程序上使用了
$(元素)
而不是
$('#按钮1)
——希望确保更新我的不完整答案

更新#2:发现另一个问题。在DOM中找到HTML之前,已附加javascript事件处理程序。这样做的结果是事件处理程序将不会被附加。将javascript移动到HTML元素下方,或将javascript代码包装到jQuery document中。就绪代码如下:

$( document ).ready(function() {
    // your js code here
});
更新#3:ajax调用本身没有足够的属性来实际进行ajax调用。这是一个您可能想要遵循的示例。您至少需要添加类型和url。如果要传递参数,则需要数据

$.ajax({
    type: "POST",
    url: url,
    data: data,
    success: success
});
更新#4:这里有一个更完整的代码片段,希望能引导您找到解决方案:

<script type="text/javascript">

// execute the javascript action after the entire DOM has been loaded
$( document ).ready(function() {

    // hide the image initially
    $(".loading-gif").hide();

    // attach the handler to the button
    $('#Button1').click(function () {
        $(".loading-gif").show();

        // provide enough information to the ajax function to make a call
        $.ajax({
            type: "POST",
            url: "some-other-page.html",
            success: function () {
                $(".loading-gif").hide();
            }
        });
    });
});
</script>

<div class="ajax-content">
    <img src="http://localhost:2169/Image/Icon/loading.gif" alt="Loading" class="loading-gif" />
    <div class="ajax-response">
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
</div>

//在加载整个DOM后执行javascript操作
$(文档).ready(函数(){
//最初隐藏图像
$(“.loading gif”).hide();
//将处理程序附加到按钮
$('#按钮1')。单击(函数(){
$(“.loading gif”).show();
//向ajax函数提供足够的信息以进行调用
$.ajax({
类型:“POST”,
url:“其他页面.html”,
成功:函数(){
$(“.loading gif”).hide();
}
});
});
});

您在javascript中使用类
导航jpg
,但在HTML中使用类
加载gif
。保持一致,你就是好人

更新:其他回答者也发现在事件处理程序上使用了
$(元素)
而不是
$('#按钮1)
——希望确保更新我的不完整答案

更新#2:发现另一个问题。在DOM中找到HTML之前,已附加javascript事件处理程序。这样做的结果是事件处理程序将不会被附加。将javascript移动到HTML元素下方,或将javascript代码包装到jQuery document中。就绪代码如下:

$( document ).ready(function() {
    // your js code here
});
更新#3:ajax调用本身没有足够的属性来实际进行ajax调用。这是一个您可能想要遵循的示例。您至少需要添加类型和url。如果要传递参数,则需要数据

$.ajax({
    type: "POST",
    url: url,
    data: data,
    success: success
});
更新#4:这里有一个更完整的代码片段,希望能引导您找到解决方案:

<script type="text/javascript">

// execute the javascript action after the entire DOM has been loaded
$( document ).ready(function() {

    // hide the image initially
    $(".loading-gif").hide();

    // attach the handler to the button
    $('#Button1').click(function () {
        $(".loading-gif").show();

        // provide enough information to the ajax function to make a call
        $.ajax({
            type: "POST",
            url: "some-other-page.html",
            success: function () {
                $(".loading-gif").hide();
            }
        });
    });
});
</script>

<div class="ajax-content">
    <img src="http://localhost:2169/Image/Icon/loading.gif" alt="Loading" class="loading-gif" />
    <div class="ajax-response">
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
</div>

//在加载整个DOM后执行javascript操作
$(文档).ready(函数(){
//最初隐藏图像
$(“.loading gif”).hide();
//将处理程序附加到按钮
$('#按钮1')。单击(函数(){
$(“.loading gif”).show();
//向ajax函数提供足够的信息以进行调用
$.ajax({
类型:“POST”,
url:“其他页面.html”,
成功:函数(){
$(“.loading gif”).hide();
}
});
});
});

您在javascript中使用类
导航jpg
,但在HTML中使用类
加载gif
。保持一致,你就是好人

更新:其他回答者也发现在事件处理程序上使用了
$(元素)
而不是
$('#按钮1)
——希望确保更新我的不完整答案

更新#2:发现另一个问题。在DOM中找到HTML之前,已附加javascript事件处理程序。这样做的结果是事件处理程序将不会被附加。将javascript移动到HTML元素下方,或将javascript代码包装到jQuery document中。就绪代码如下:

$( document ).ready(function() {
    // your js code here
});
更新#3:ajax调用本身没有足够的属性来实际进行ajax调用。这是一个您可能想要遵循的示例。您至少需要添加类型和url。如果要传递参数,则需要数据

$.ajax({
    type: "POST",
    url: url,
    data: data,
    success: success
});
更新#4:这里有一个更完整的代码片段,希望能引导您找到解决方案:

<script type="text/javascript">

// execute the javascript action after the entire DOM has been loaded
$( document ).ready(function() {

    // hide the image initially
    $(".loading-gif").hide();

    // attach the handler to the button
    $('#Button1').click(function () {
        $(".loading-gif").show();

        // provide enough information to the ajax function to make a call
        $.ajax({
            type: "POST",
            url: "some-other-page.html",
            success: function () {
                $(".loading-gif").hide();
            }
        });
    });
});
</script>

<div class="ajax-content">
    <img src="http://localhost:2169/Image/Icon/loading.gif" alt="Loading" class="loading-gif" />
    <div class="ajax-response">
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
</div>

//在加载整个DOM后执行javascript操作
$(文档).ready(函数(){
//最初隐藏图像
$(“.loading gif”).hide();
//将处理程序附加到按钮
$('#按钮1')。单击(函数(){
$(“.loading gif”).show();
//向ajax函数提供足够的信息以进行调用
$.ajax({
类型:“POST”,
url:“其他页面.html”,
成功:函数(){
$(“.loading gif”).hide();
}
});
});
});

您在javascript中使用类
导航jpg
,但在HTML中使用类
加载gif
。保持一致,你就是好人

更新:其他回答者也发现在事件处理程序上使用了
$(元素)
而不是
$('#按钮1)
——希望确保更新我的不完整答案

更新#2:发现另一个问题。在DOM中找到HTML之前,已附加javascript事件处理程序。其结果是事件处理程序将