Firefox表单提交问题与jQuery

时间:2022-11-23 18:28:48

I am using the following script to submit a form with jQuery, however Firefox has generated a crash error report, please let me know what am I doing wrong.

我正在用下面的脚本提交一个jQuery表单,但是Firefox已经生成了一个崩溃错误报告,请让我知道我做错了什么。

function teamValidation(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
        $('#addForm').submit(); 
        return false;
    }
}

<form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" 
 name="addForm" id="addForm" onsubmit="return teamValidation();">
 <input type="hidden" name="cat_id" id="cat_id" value="1"/>
</form>

Firefox error report

Firefox错误报告

Firefox表单提交问题与jQuery

It is working fine in other browsers.

它在其他浏览器中运行良好。

4 个解决方案

#1


5  

The problem is your form is submitting multiple times.You can achieve your goal using any of the following ways:
HTML:

问题是你的表单提交了很多次。你可以通过以下任何一种方式来达到你的目标:HTML:

<form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm">
 <input type="hidden" name="cat_id" id="cat_id" value="1"/>
</form>

JAVASCRIPT:

JAVASCRIPT:

$('#addForm').submit(function(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
        return true;
    }
});

Another Way:
HTML:

另一种方法:HTML:

<form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm" onsubmit="return teamValidation();">
     <input type="hidden" name="cat_id" id="cat_id" value="1"/>
    </form>

JAVASCRIPT:

JAVASCRIPT:

function teamValidation(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
       return true;
    }
}

#2


2  

You have an infinite loop of submitting, then preventing the submission of, your form when the value of the cat_id text box is not 0. Remove the else block, since it serves no actual purpose.

当cat_id文本框的值不为0时,您有一个无限的提交循环,然后阻止您的表单的提交。删除else块,因为它没有实际用途。

To go into more detail:

更详细地说:

function teamValidation(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
        $('#addForm').submit(); // this submits the form again - does NOT proceed with this submission of the form
        return false; // returning false will prevent the submission from being completed
    }
}

<form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" 
 name="addForm" id="addForm" onsubmit="return teamValidation();">
 <input type="hidden" name="cat_id" id="cat_id" value="1"/>
</form>

When you submit the form, teamValidation() gets called. If the validation passes (the else block code is executed), you submit the form again which causes teamValidation() to be called yet again, then return false which will prevent this current submission from completing. Firefox is likely crashing because it finds itself in a loop where it's constantly submitting a form, which is never allowed to complete; the fact the browser is pretty awful in terms of memory usage probably doesn't help either.

提交表单时,将调用teamValidation()。如果验证通过(执行else块代码),您将再次提交表单,从而再次调用teamValidation(),然后返回false,这将阻止当前提交完成。Firefox可能会崩溃,因为它发现自己处于一个循环中,它不断地提交表单,这是不允许完成的;浏览器在内存使用方面非常糟糕的事实可能也没有帮助。

#3


0  

You forgot to close your function definition

你忘记关闭函数定义了

function teamValidation(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
        $('#addForm').submit(); 
        return false;
    }
} <--- this

#4


0  

You missed a '}' at the end. Still, It should not cause a crash. 99% a problem with your Firefox Installation. I just checked with mine here. Works correctly. There is no problem with your code. Try Uninstalling and reinstalling Firefox.

最后你漏了一个'}'。不过,它不应导致崩盘。99%的问题,你的Firefox安装。我刚在这里查过了。正确地工作。你的代码没有问题。尝试卸载和重新安装Firefox。

Another discovery. Your form is being submitted indefinitely. Maybe your other browsers are newer and your Firefox is outdated (not capable of handling indefinite recursions which is why it may be crashing).

另一个发现。您的表格将被无限期地提交。也许你的其他浏览器是更新的,你的Firefox是过时的(不能处理不确定的递归,这就是为什么它可能会崩溃)。

Anyways, try replacing the following:

不管怎样,试着替换以下内容:

$('#addForm').submit();

with:

:

document.getElementById("addForm").submit();

Hope that helps..

希望帮助. .

Peace be upon you...

平安在你…

#1


5  

The problem is your form is submitting multiple times.You can achieve your goal using any of the following ways:
HTML:

问题是你的表单提交了很多次。你可以通过以下任何一种方式来达到你的目标:HTML:

<form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm">
 <input type="hidden" name="cat_id" id="cat_id" value="1"/>
</form>

JAVASCRIPT:

JAVASCRIPT:

$('#addForm').submit(function(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
        return true;
    }
});

Another Way:
HTML:

另一种方法:HTML:

<form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" name="addForm" id="addForm" onsubmit="return teamValidation();">
     <input type="hidden" name="cat_id" id="cat_id" value="1"/>
    </form>

JAVASCRIPT:

JAVASCRIPT:

function teamValidation(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
       return true;
    }
}

#2


2  

You have an infinite loop of submitting, then preventing the submission of, your form when the value of the cat_id text box is not 0. Remove the else block, since it serves no actual purpose.

当cat_id文本框的值不为0时,您有一个无限的提交循环,然后阻止您的表单的提交。删除else块,因为它没有实际用途。

To go into more detail:

更详细地说:

function teamValidation(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
        $('#addForm').submit(); // this submits the form again - does NOT proceed with this submission of the form
        return false; // returning false will prevent the submission from being completed
    }
}

<form action="<?php echo SITE_URL; ?>adminteams/saveDetail/" 
 name="addForm" id="addForm" onsubmit="return teamValidation();">
 <input type="hidden" name="cat_id" id="cat_id" value="1"/>
</form>

When you submit the form, teamValidation() gets called. If the validation passes (the else block code is executed), you submit the form again which causes teamValidation() to be called yet again, then return false which will prevent this current submission from completing. Firefox is likely crashing because it finds itself in a loop where it's constantly submitting a form, which is never allowed to complete; the fact the browser is pretty awful in terms of memory usage probably doesn't help either.

提交表单时,将调用teamValidation()。如果验证通过(执行else块代码),您将再次提交表单,从而再次调用teamValidation(),然后返回false,这将阻止当前提交完成。Firefox可能会崩溃,因为它发现自己处于一个循环中,它不断地提交表单,这是不允许完成的;浏览器在内存使用方面非常糟糕的事实可能也没有帮助。

#3


0  

You forgot to close your function definition

你忘记关闭函数定义了

function teamValidation(){
    var cat_id = $('#cat_id').val();    

    if(cat_id == "0"){
        alert("Category is invalid...");    
        return false;
    }else{
        $('#addForm').submit(); 
        return false;
    }
} <--- this

#4


0  

You missed a '}' at the end. Still, It should not cause a crash. 99% a problem with your Firefox Installation. I just checked with mine here. Works correctly. There is no problem with your code. Try Uninstalling and reinstalling Firefox.

最后你漏了一个'}'。不过,它不应导致崩盘。99%的问题,你的Firefox安装。我刚在这里查过了。正确地工作。你的代码没有问题。尝试卸载和重新安装Firefox。

Another discovery. Your form is being submitted indefinitely. Maybe your other browsers are newer and your Firefox is outdated (not capable of handling indefinite recursions which is why it may be crashing).

另一个发现。您的表格将被无限期地提交。也许你的其他浏览器是更新的,你的Firefox是过时的(不能处理不确定的递归,这就是为什么它可能会崩溃)。

Anyways, try replacing the following:

不管怎样,试着替换以下内容:

$('#addForm').submit();

with:

:

document.getElementById("addForm").submit();

Hope that helps..

希望帮助. .

Peace be upon you...

平安在你…