未捕获的RangeError:最大调用堆栈

时间:2015-07-26 21:06:55

标签: php jquery ajax

我有一个带有表单的页面。我正在尝试将该表单发送到另一个页面以便使用AJAX进行处理。但是无论何时调用AJAX,我都会得到一个Uncaugh RangeError。

我通过Jquery CDN使用最新版本的jQuery,所有其他jQuery都在我的页面上工作,所以我知道我的代码必须存在问题。

这是错误

Uncaught RangeError: Maximum call stack size exceededn.param.e @ jquery.js:8454Ac @ jquery.js:8442Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:8437Ac @ jquery.js:843

这是我的表格代码

<form role="form" name="ipcrStep1" id="ipcrStep1" class="step">

    <div class="panel panel-default">
        <div class="panel-heading">
                <i class="fa fa-user-md fa-fw"></i> Call Information
                <span class="pull-right">Step 1 of 15</span>
            </ul>
        </div>
        <div class="panel-body">
        <fieldset>
            <div class="row">
                <div class="col-lg-6">

                        <fieldset disabled>
                            <div class="form-group">
                                <label for="disabledSelect">Technician 1 Name</label>
                                <input required class="form-control" type="text" name="ipcrTech1Name" value="<?php echo $_SESSION['currentUserName']; ?>" disabled>
                                <p class="help-block">Primary Technician in charge of call. Field auto-populated from login information.</p>
                            </div>
                            <div class="form-group">
                                <label for="disabledSelect">Technician 1 ID Number</label>
                                <input required class="form-control" itype="text" name="ipcrTech1EMTID" value="<?php echo $_SESSION['currentUserEMTID']; ?>" disabled>
                                <p class="help-block">Primary Technician in charge of call. Field auto-populated from login information.</p>
                            </div>
                        </fieldset>
                        <div class="form-group">
                            <label>Technician 2 Name</label>
                            <select required class="form-control" name="ipcrTech2Name">
                                <option value="">Jason Smith</option>
                                <option value="">John Smith</option>
                                <option value="">Josh Smith</option>
                            </select>
                        </div>
                        <fieldset disabled>
                            <div class="form-group">
                                <label for="disabledSelect">Technician 2 ID Number</label>
                                <input required class="form-control" type="text" name="ipcrTech2EMTID" value="<?php echo $_SESSION['currentUserEMTID']; ?>" disabled>
                                <p class="help-block">Assistant or Additional EMT. Field auto-populated from Technician 2 Selection.</p>
                            </div>
                        </fieldset>
                        <div class="form-group">
                            <label>Service Date</label>
                            <input required class="form-control" type="text" name="ipcrServiceDate">
                            <p class="help-block">Enter date in the following format MM-DD-YYYY.</p>
                        </div>
                        <div class="form-group">
                            <label>Paper IPCR #</label>
                            <input required class="form-control" type="text" name="ipcrPaperIPCRNum">
                            <p class="help-block">Usefull for searching database.</p>
                        </div>
                        <div class="form-group">
                            <label>Responding Apperatus</label>
                            <select required class="form-control" name="ipcrApperatus">
                                <option>A18</option>
                                <option>A19</option>
                            </select>
                        </div>

                </div>
                <!-- /.col-lg-6 (nested) -->
                <div class="col-lg-6">

                        <div class="form-group">
                            <label>Call Code</label>
                            <input required class="form-control" type="text" name="ipcrCallCode">
                            <p class="help-block">Code as reported by 911.</p>
                        </div>    
                        <div class="form-group">
                            <label>Dispatch Type</label>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrDispatchCode" value="A" checked>Code A - Non-Emergent
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrDispatchCode" value="B">Code B - Non-emergent
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrDispatchCode" value="C">Code C - Emergent
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrDispatchCode" value="D">Code D - Arrest/Critical
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrDispatchCode" value="T">Transfer
                                </label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>Disposition/Call Outcome</label>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Transport Routine" checked>Transport Routine
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Transport Emergency">Transport Emergency
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Refusal Treatment
                                </label>">Refusal Treatment
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Treated - Released">Treated - Released
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Transfer To Another Unit">Transfer To Another Unit
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Treated - Refused Transport">Treated - Refused Transport
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="D.O.A.">D.O.A.
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="False Call">False Call
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Canceled">Canceled
                                </label>
                            </div>
                            <div class="radio">
                                <label>
                                    <input type="radio" name="ipcrTransportType" value="Standby">Standby
                                </label>
                            </div>
                        </div>

                        <input type="hidden" name="zipcode" value="<?php echo $_SESSION['currentUserZip']; ?>">
                        <input type="hidden" name="user_id" value="<?php echo $_SESSION['logSyscuruser']; ?>">
                        <input type="hidden" name="username" value="<?php echo $_SESSION['user_login']; ?>">
                        <input type="hidden" name="ipcrStepNum" value="1">
                        <input type="hidden" name="created" value="<?php echo $ipcrCreated; ?>">
                        <input type="hidden" name="ipcrExpires" value="<?php echo $ipcrExpires; ?>">
                        <input type="hidden" name="ipcrPCRID" value="<?php echo $ipcrPCRID; ?>">

                </div>
                <!-- /.col-lg-6 (nested) -->
            </div>
            <!-- /.row (nested) -->
        </fieldset>
        </div>
        <!-- /.panel-body -->
        <div class="panel-footer">
            <button type="button" id="saveBtnStep1" class="btn btn-lg btn-primary">Save</button>
        </div>
    </div>
    <!-- /.panel -->

</form>

这是我发送表格数据的AJAX

<script>

    // PREPARES JQUERY FUNCTIONS ON DOCUMENT LOAD FOR QUICKER ACCESS

    $(document).ready(function(){

        //THIS SECTION PROCCESSES THE FORM WHEN CLICKING THE SUBMIT BUTTON

        $('#saveBtnStep1').on('click', function(){

            // FIND FORM DATA FIELDS

            var findform = $(document).find('#ipcrStep1');
            var ipcrTech1Name = findform.find("input[name='ipcrTech1Name']").val();
            var ipcrTech1EMTID = findform.find("input[name='ipcrTech1EMTID']").val();
            var ipcrTech2Name = findform.find("select[name='ipcrTech2Name']").val();
            var ipcrTech2EMTID = findform.find("input[name='ipcrTech2EMTID']").val();
            var ipcrServiceDate = findform.find("input[name='ipcrServiceDate']").val();
            var ipcrPaperIPCRNum = findform.find("input[name='ipcrPaperIPCRNum']").val();
            var ipcrApperatus = findform.find("select[name='ipcrApperatus']").val();
            var ipcrCallCode = findform.find("input[name='ipcrCallCode']").val();
            var ipcrDispatchCode = findform.find("radio[name='ipcrDispatchCode']").val();
            var ipcrTransportType = findform.find("radio[name='ipcrTransportType']").val();
            var zipcode = findform.find("input[name='zipcode']").val();
            var user_id = findform.find("input[name='user_id']").val();
            var username = findform.find("input[name='username']").val();
            var ipcrStepNum = findform.find("input[name='ipcrStepNum']").val();
            var created = findform.find("input[name='created']").val();
            var ipcrExpires = findform.find("input[name='ipcrExpires']").val();
            var ipcrPCRID = findform.find("input[name='ipcrPCRID']").val();

            // AJAX SENDS THE FORM CODE TO THE PHP PROCESSING PAGE ACCORDING TO STEP NUMBER

            $.ajax({
                type : 'POST',
                url : '/processipcr/step1.php',
                dataType : 'json',
                data: {
                    findform : findform,
                    ipcrTech1Name : ipcrTech1Name,
                    ipcrTech1EMTID : ipcrTech1EMTID,
                    ipcrTech2Name : ipcrTech2Name,
                    ipcrTech2EMTID : ipcrTech2EMTID,
                    ipcrServiceDate : ipcrServiceDate,
                    ipcrPaperIPCRNum : ipcrPaperIPCRNum,
                    ipcrApperatus : ipcrApperatus,
                    ipcrCallCode : ipcrCallCode,
                    ipcrDispatchCode : ipcrDispatchCode,
                    ipcrTransportType : ipcrTransportType,
                    zipcode : zipcode,
                    user_id : user_id,
                    username : username,
                    ipcrStepNum : ipcrStepNum,
                    created : created,
                    ipcrExpires : ipcrExpires,
                    ipcrPCRID : ipcrPCRID
                },

                // ONCE THE FORM HAS BEEN PROCESSING AT THE PROCESSING PAGE THIS CODE ENABLES THE NEXT STEP

                success: function(e){

                    // BLOCK DEFAULT FORM OPERATIONS

                    e.preventDefault();

                    // ALERT MESSAGE UPON SUCCESSFUL UPDATE TO DATABASE

                    alert('Your progress has been save. Click okay to continue to Step 2.');

                    // THIS CODE EMABLES THE NEXT SECTION OF THE PAGE

                    var findStep2 = $(document).find('#ipcrStep2');
                        findStep2.find('.panel').removeClass('panel-disabled');
                        findStep2.find('fieldset').removeAttr('disabled');
                        findStep2.find('#backBtnStep2').removeAttr('disabled');
                        findStep2.find('#saveBtnStep2').removeAttr('disabled');

                        // THIS CODE ACTIVATES HIDDEN SCROLL ANCHOR AT THE BOTTOM OF THE PAGE

                        $(document).find('#stepScroll2').trigger('click');

                }

            });

        });

    });

</script>

1 个答案:

答案 0 :(得分:0)

您已经提交表单提交很久!!!您无法将e.preventDefault();置于Ajax success:回调中并期望它能够正常运行。那太晚了。

此外,您不应该使用按钮单击来捕获表单提交,因为按键也可以触发表单提交。始终使用form事件。

例如:下面我删除了大部分代码,以澄清一个使用sentinel变量控制表单是否允许正常提交的简单模式。

$(document).ready(function(){
    var allowSubmit = false;
    $('#ipcrStep1').on('submit', function(e){
        if (!allowSubmit){
            // FIND FORM DATA FIELDS
            // AJAX SENDS THE FORM CODE TO THE PHP PROCESSING PAGE ACCORDING TO   
            $.ajax({
                type : 'POST',
                url : '/processipcr/step1.php',
                dataType : 'json',
                data: {...},

                // ONCE THE FORM HAS BEEN PROCESSING AT THE PROCESSING PAGE THIS CODE ENABLES THE NEXT STEP

                success: function(e){

                    // ALLOW NEXT SUBMIT TO WORK NORMALLY
                    allowSubmit = true;

                    // ALERT MESSAGE UPON SUCCESSFUL UPDATE TO DATABASE

                    // THIS CODE ENABLES THE NEXT SECTION OF THE PAGE (FORM???)
                    $(document).find('#form2').trigger('submit');
                }
            });
        }
        return allowSubmit;
    });
});

其他选项包括将处理程序与onoff相关联,以便您可以启用一个表单并禁用之前的表单。