当我提交表单时,我得到Uncaught RangeError:超出了最大调用堆栈大小

I am trying to POST a form to my testexe.php using an Ajax request, however, whenever I add the data type gateway in my Ajax request I get the Uncaught RangeError: Maximum call stack size exceeded error message. Is there something I am doing wrong here? I am able to get the button value successfully but not sure why gateway is giving me problems.

<!DOCTYPE html>
<html>
<head>
<style>
    .box1 {
        width: 450px;
        border: 2px solid black;
        margin: 0;
        display: flex;
    }

    .col {
        display: inline-block;
        border-right: 2px solid black;
        padding: 5px;
        width: 200px;
    }

    .col:last-child {
        border-right: none;
    }

    input[type=text], select {
            width: 20%;
            padding: 12px 20px;
            margin: 8px 0;
            display: inline-block;
                border: 1px solid #ccc;
                border-radius: 4px;
                box-sizing: border-box;
                background-color: #ffffff;
        }
</style>
</head>
<body>
<div id="gatewayInput">
<form method="post">
      <input type="text" id="gateway" name="gateway" placeholder="Gateway Name"><br><br>
      <?php 
        include("search.php"); 
      ?>    
</div>
<div class="box1">  
<label class="col">Up/Down</label>
<span class="col">
  <input type="radio" name="option" id="r1" value="1" />
  <label for="r1">Up</label>
  <input type="radio" name="option" id="r2" value="2" />
  <label for="r2">Down</label> 
</span>
 <span class="col">
  <input type="submit" class="button" name="submit"/>
 </span>
  </form>
</div>
<script src ="../../../jqueryDir/jquery-3.2.1.min.js"></script>
<script src ="../../../jqueryDir/jquery-ui.min.js"></script>
<script type="text/javascript">

  //auto seatch function
  $(function() {
      $( "#gateway" ).autocomplete({
          source: 'search.php'
      });
  });

  //button click function
    $(".button").click(function(event){
        if ((document.getElementsByName("gateway")[0].value == '')) {
               alert('Gateway Required!');
        return false;
    }
        else if (document.querySelectorAll('input[type="radio"]:checked').length < 1) {
               alert('Please Choose Value!');
               return false;
        } 
        else {
               //alert('Sucess!');
            event.preventDefault();
            $.ajax({
            url:"testexe.php",
            type: "POST",
                    data: {
              gateway: gateway,   //when I add this it give me the error
              option: $('input[type=radio]:checked').val() 
            },
            dataType: "text", 
            success:function(result){
                        $('#div1').html(result)
            }
            });
             return true;
        }
  });

</script>
<div id="div1"></div>
</body>
</html>

testexe.php

<?php
//when the submit button is clicked
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
  echo "yay I got the POST!";
  if(isset($_POST['gateway']){
    $gateway = $_POST['gateway'];
    echo $gateway;
  }
}

(removed code for simplicity)
?>

search.php

<?php
//database configuration
$dbHost = 'localhost';
$dbUsername = 'user';
$dbPassword = '';
$dbName = 'database';

//connect with the database
$db = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);


if(isset($_GET['term'])){
    //get search term
    $searchTerm = $_GET['term'];

    //get matched data from skills table
    $query = $db->query("SELECT * FROM table WHERE tablename LIKE '%".$searchTerm."%' ORDER BY tablename ASC");

    while ($row = $query->fetch_assoc()) {
        $data[] = $row['tablename'];
    }

    //return json data
    echo json_encode($data);
    mysqli_close($db);
}
?>

error message:

Uncaught RangeError: Maximum call stack size exceeded
at Function.type (jquery-3.2.1.min.js:2)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
at Ab (jquery-3.2.1.min.js:4)
dsxjot8620
dsxjot8620 你的意思是这个网关:$(“#gateway”),?
大约 3 年之前 回复
dougu8742
dougu8742 您似乎没有定义.ajax()中使用的JavaScript变量网关。您需要实际从表单中获取元素并将其分配给此变量。
大约 3 年之前 回复

1个回答



在这里你得到一个解决方案</ p>

  $。ajax({
url :“testexe.php”,
类型:“POST”,
data:{
gateway:$(“#gateway”)。val(),
option:$('input [type = radio]: 选中')。val()
},
dataType:“text”,
success:function(result){
$('#div1')。html(result)
}
});

</ code> </ pre>

错误是 gateway:gateway </ code>。
我假设您要从<传递 gateway </ code>值 代码>输入文本框</ code>。</ p>

更改代码 gateway:$(“#gateway”)。val(),</ code> </ p>
\ n

希望这会对你有所帮助。</ p>
</ div>

展开原文

原文

Here you go with a solution

$.ajax({
  url:"testexe.php",
  type: "POST",
  data: {
    gateway: $("#gateway").val(),
    option: $('input[type=radio]:checked').val() 
  },
  dataType: "text", 
  success: function(result){
    $('#div1').html(result)
  }
});

Mistakes was gateway: gateway. I assume you want to pass the gateway value from the input textbox.

Changed code gateway: $("#gateway").val(),

Hope this will help you.

dongxia9620
dongxia9620 谢谢,这很有效。
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐