JavaScript的:功能不工作没有警报() [英] JavaScript: function not working without alert()

查看:158
本文介绍了JavaScript的:功能不工作没有警报()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的解决方法

您好,各位程序员!

我写信给你,以请求一些帮助,我最近经历的问题。非常问题如下:

I am writing to you in order to request some help with an issue I recently experienced. The very issue is as follows:

1)我有一个Ajax请求,使用jQuery实现的。

1) I have an ajax request, implemented with jQuery.

2)返回一个成功的响应后,将脚本应该重新加载该页面与相应的变化,如果有任何验证错误,一个隐藏的字段,用于存储非关键杂数据之后将其插入。如果有任何验证错误,更改不保存,并且在页面重新加载刚刚与验证错误消息。验证本身是采取由一个servlet照顾。

2) After returning a successful response, the script should reload the page with the respective changes and if there are any validation errors, insert them after a hidden field, used to store non-critical miscellaneous data. If there are any validation errors, the changes are not saved and the page is just reloaded with the validation error messages. The validation itself is taken care of by a servlet.

3)我发现一切正常,当任何警报()是错误消息的实际追加前psented $ P $,但我不希望有这样的提示。

3) I noticed that everything works fine, when any kind of alert() is presented before the actual appending of the error messages, but I do not want to have such an alert.

下面是JavaScript code:

Here is the JavaScript code:

$('#randomFormElement').submit(function() {
        $(this).ajaxSubmit({
            success: function (data, status) {
                randomFunctionToReloadThePage(arg1, arg2, arg3);
                var errors = $(data).find('.classNameOfTheErrors').xml();
                //alert(something);
                $(errors).insertAfter('#idOfTheHiddenField');
            },
            error: function (jqXHR, textStatus, thrownError) {
            //Error handling if the ajax response fails.
            }
         });
});

所以,主要的问题是:什么是处理警报()使其工作

So, the main question is: what's the deal with alert() making it work?

==========================

==========================

在Chrome浏览器,它并没有任何一种方式工作。

On Chrome, it doesn't work either way.

在FF,它的工作只有当某些警报()是present。

On FF, it does work only when some alert() is present.

在此先感谢!

推荐答案

感谢大家的回答,特别是gvee的回答,我设法得到它的工作。很明显,确实有一些异步的randomFunctionToReloadThePage()怎么回事,我设法使用 .ajaxStop修复( )方法。​​

Thanks to everyone's answers, and gvee's answer in particular, I managed to get it work. Obviously, there was indeed something asynchronous going on in the randomFunctionToReloadThePage(), and I managed to fix it using the .ajaxStop() method.

编辑:第二个错误是在使用ajaxStop发现()。我找到了解决办法,以正确的工作如下:

a second bug was found while using ajaxStop(). The solution I found to be working properly is as follows:

1)添加一个额外的参数给randomFunctionToReloadThePage

1) Add an extra parameter to the randomFunctionToReloadThePage

2)调用函数在各自的页面,额外的参数。

2) Invoke the function with that extra parameter in the respective page.

这篇关于JavaScript的:功能不工作没有警报()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆