Javascript 当我提交表单时,我得到了未捕获的RangeError:超过了最大调用堆栈大小
我试图使用Ajax请求将表单发布到我的Javascript 当我提交表单时,我得到了未捕获的RangeError:超过了最大调用堆栈大小,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我试图使用Ajax请求将表单发布到我的testexe.php,但是,每当我在Ajax请求中添加数据类型网关时,我都会收到未捕获的RangeError:超出最大调用堆栈大小的错误消息。我有什么地方做错了吗?我能够成功地获取按钮值,但不确定为什么网关会给我带来问题 <!DOCTYPE html> <html> <head> <style> .box1 { width: 450px; border: 2px sol
testexe.php
,但是,每当我在Ajax请求中添加数据类型网关时,我都会收到未捕获的RangeError:超出最大调用堆栈大小的错误消息。我有什么地方做错了吗?我能够成功地获取按钮值
,但不确定为什么网关
会给我带来问题
<!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>
给你一个解决方案
$.ajax({
url:"testexe.php",
type: "POST",
data: {
gateway: $("#gateway").val(),
option: $('input[type=radio]:checked').val()
},
dataType: "text",
success: function(result){
$('#div1').html(result)
}
});
错误是gateway:gateway
。
我假设您想从输入文本框
传递网关
值
更改代码gateway:$(“#gateway”).val(),
希望这对你有帮助
gateway: $("#gateway").val(),
您必须像对待选项一样,使用此方法获取网关的值
gateway: gateway, //when I add this it give me the error
option: $('input[type=radio]:checked').val()
您似乎没有定义
.ajax()
中使用的JavaScript变量gateway
。您需要从表单中实际获取元素并将其分配给此变量。@ObsidManager您的意思是像这样的网关:$(“#网关”),
?
$.ajax({
url:"testexe.php",
type: "POST",
data: {
gateway: $("#gateway").val(),
option: $('input[type=radio]:checked').val()
},
dataType: "text",
success: function(result){
$('#div1').html(result)
}
});
gateway: $("#gateway").val(),
gateway: gateway, //when I add this it give me the error
option: $('input[type=radio]:checked').val()