ajax 图像未显示在表单提交上,但在 Firefox 中显示正常

发布于 2024-12-25 07:26:44 字数 549 浏览 1 评论 0原文

这是我用来在表单提交上显示 ajax 图像的代码:

$(document).ready(function() { 

    $('#form_id').bind('submit', function() {
      $('#img-div').show();
    });
    $('#form_id').submit('submit', function(event) { 
        event.preventDefault();
..........................
......................
    });

});

这在一个页面中工作正常,但在不同页面中则不然。 在 Firefox 上,两个页面都工作正常。

上面的代码可能有什么问题...

编辑:

这只发生在一种特定情况下。 AJAX 调用使页面无响应并且图像不显示,如果我显示加载图像,它会在 ajax 调用期间停止动画。我尝试使用 jQuery UI 对话框,结果仍然相同,但在 Firefox 上工作正常。 。

Here is the code am using to show an ajax image on form submit:

$(document).ready(function() { 

    $('#form_id').bind('submit', function() {
      $('#img-div').show();
    });
    $('#form_id').submit('submit', function(event) { 
        event.preventDefault();
..........................
......................
    });

});

This works fine in one page, and doesn't in a different page.
Where as on Firefox both pages work fine.

What could be wrong in the above code...

EDIT:

This only happens in one particular case. The AJAX call makes the page unresponsive and the image does not show, if I show a loading image, it stops animating for the duration of ajax call., I tried using jQuery UI dialog, still same result, works fine on Firefox though...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

予囚 2025-01-01 07:26:44

好的。 .bind('submit',function(){}) 类似于 .submit(function(){})。并且 .submit() 函数不需要“submit”作为参数。

我认为您想要的代码是这样的:

$(document).ready(function() { 
    $('#form_id').submit(function(event) { 
        event.preventDefault()
        $('#img-div').show()
        //......................
        //......................
    })
})

尝试一下并让我知道。我怀疑 Firefox 可能对你损坏的代码更宽容,而其他浏览器只是在遇到它时就崩溃了。

OK. .bind('submit',function(){}) is analogous to .submit(function(){}). And the .submit() function doesn't need 'submit' as an argument.

I think the code you want is this:

$(document).ready(function() { 
    $('#form_id').submit(function(event) { 
        event.preventDefault()
        $('#img-div').show()
        //......................
        //......................
    })
})

Try that and let me know. I suspect Firefox may have been more tolerant to your broken code, whereas other browsers just broke when it hit it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文