【问题标题】:i am getting stack : Maximum call stack size exceeded error我正在获取堆栈:超出最大调用堆栈大小错误
【发布时间】:2018-06-08 05:47:35
【问题描述】:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<body>

<h2>HTML Forms</h2>

<form  name = "test_form">
  First name:<br>
  <input type="text" name="firstname" value="Mickey">
  <br>
  Last name:<br>
  <input type="text" name="lastname" value="Mouse">
  <br><br>
  <input type="button" value="Submit" >
</form>

<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>
<script>

var url = "http://x.x.x.x:3001/createData"
var data ={
    "productID": document.test_form.firstname,
    "title": document.test_form.lastname,


};
var success_func = function(data){
    //do what you want with the returned data
 console.log("your data is succesfull posted")
};
$.post(url, data, success_func);

</script>
</body>
</html>

我没有通过任何事情,也只是调用其余 api 并发布数据,但我得到堆栈最大大小超出错误请帮助我

【问题讨论】:

  • 删除提交按钮并在表单外创建一个新按钮或元素...在其上添加一个事件并继续您的任务。
  • 将此&lt;input type="submit" value="Submit" &gt; 转换为此&lt;input type="button" value="Submit" &gt;
  • 好吧......你从来没有打电话给fck......那它为什么会执行呢?你认为浏览器如何知道运行 fck
  • 除非你想暴露你的服务器,否则不要硬 cdoe ip 地址。

标签: javascript html css json api


【解决方案1】:

在你的代码中试试这个并检查它是否有效

function goodCall(){
  var url = "http://34.201.147.118:3001/createData"
  var data ={
    "productID": document.test_form.firstname.value,
    "title": document.test_form.lastname.value,
  }
  $.post( url, function( data ) {
    sucess_func();
  });
};

function success_func(data) {
  console.log('data posted')
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>HTML Forms</h2>

<form  name = "test_form">
  First name:<br>
  <input type="text" name="firstname" value="Mickey">
  <br>
  Last name:<br>
  <input type="text" name="lastname" value="Mouse">
  <br><br>
  <input type="button" onClick="goodCall()" value="Submit" >
</form>

<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>

【讨论】:

  • 它可以工作,但我收到以下错误 jquery.min.js:4 POST 34.201.147.118:3001/createData 500 (Internal Server Error) 但在 post man 中测试 api 时它工作正常
  • 34.201.147.118:3001/createData {"productID":"1014", "title":"Movie1" } 如果您只想通过邮递员进行测试,请帮助我
  • 我们无法从这里进行测试,这意味着可能会导致 CORS 问题。您需要在您的环境中对其进行测试。
  • 500 Internal Server Error 是一个非常普遍的 HTTP 状态代码,表示网站服务器出现问题,但服务器无法更具体地说明问题所在。所以你最好检查一下 BE 代码本身。您可能会从身边或后端遗漏一些东西。
【解决方案2】:

试试这个我认为它现在的工作

function fck(){
debugger;
var url = "http://34.201.147.118:3001/createData"
var data ={
    productID: $("#txt1").val(),
    title: $("#txt2").val(),


};
var success_func = function(data){
    //do what you want with the returned data
 alert("your data is succesfull posted")
};
$.post(url, data, success_func);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h2>HTML Forms</h2>

<form  name = "test_form">
  First name:<br>
  <input type="text" name="firstname" value="Mickey" id="txt1">
  <br>
  Last name:<br>
  <input type="text" name="lastname" value="Mouse" id="txt2">
  <br><br>
  <input type="submit" value="Submit" onclick="fck()">
</form>

<p>If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".</p>

【讨论】:

    猜你喜欢
    • 2012-08-14
    • 2011-08-31
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多