Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t识别触发“的递归”;超过最大调用堆栈大小;错误_Javascript_Jquery_Html_Ajax_Recursion - Fatal编程技术网

Javascript Can';t识别触发“的递归”;超过最大调用堆栈大小;错误

Javascript Can';t识别触发“的递归”;超过最大调用堆栈大小;错误,javascript,jquery,html,ajax,recursion,Javascript,Jquery,Html,Ajax,Recursion,更新:我将jquery.min更改为完整版本,现在错误是: 我不熟悉JS和AJAX。我正在编写一个AJAX post请求,将登录信息(用户名和密码)提交到服务器(作为家庭作业说明的一部分提供)。My login.html看起来像: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Log into your account</tit

更新:我将jquery.min更改为完整版本,现在错误是:

我不熟悉JS和AJAX。我正在编写一个AJAX post请求,将登录信息(用户名和密码)提交到服务器(作为家庭作业说明的一部分提供)。My login.html看起来像:

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>Log into your account</title>
  <link rel="stylesheet" type="text/css" href="login.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script type="text/javascript" src="login.js"></script>
  <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js"></script>
  <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/additional-methods.js"></script>
</head>
<body>
  // A form that receives username and password as inputs

  // When you click button, func() is called
  <button type="submit" onclick="func()">Login</button>
</body>
</html>
var func = function() {
  var username = document.getElementById("username");
  var password = document.getElementById("password");
  $.ajax({
        type:"POST",
        url:url,
        data:{
            username: username,
            password: password
        },
        success: function(data){
            if(xhr.status==200){
                //If status is 200, redirect to another page
                window.location.href = '/redirect.html';
            }
            else{
                //If not, display a failure message
                alert('Login Failed.');
            }
        },
        dataType:"json"
    }
   )
 };
当我运行代码时,我在Chrome中得到一个“超过最大调用堆栈大小”错误:


我做了一些研究,发现这个错误通常是由代码中无限运行的递归函数引起的;然而,我只是不知道在我的代码中可能会出现这种潜在的递归。有人能告诉我应该怎么做吗?

我在jQuery函数名中看到了
param
,所以我怀疑它在试图编码
数据
参数时发生了这种情况。问题是您试图将DOM元素放入参数中,而不是它们的值中。改变

var username = document.getElementById("username");
var password = document.getElementById("password");
致:


我在jQuery函数名中看到
param
,因此我怀疑它在尝试编码
数据时发生了这种情况。问题是您试图将DOM元素放入参数中,而不是它们的值中。改变

var username = document.getElementById("username");
var password = document.getElementById("password");
致:


redirect.html页面加载中是否有任何逻辑?另外,请尝试添加一个错误回调函数并进行调试,以查看是否存在任何异常。@VimalanJayaGanesh redirect.html只是一个静态页面,其中包含由多个图片片段组成的映射。谢谢你的建议!是否可能是服务器导致了此问题?url变量是否正常?成功函数参数也会丢失xhr参数。你能重构你的代码吗?
document.getElementById(“用户名”)
应该是
document.getElementById(“username”).value
,密码应该是相同的(或者
$(“username”).val()
--为什么不使用jQuery函数?)。转到真正的jQuery,而不是缩小的版本(删除文件名的.min),然后我们就可以了解jQuery中的什么地方发生了redirect.html页面加载中是否有任何逻辑?另外,请尝试添加一个错误回调函数并进行调试,以查看是否存在任何异常。@VimalanJayaGanesh redirect.html只是一个静态页面,其中包含由多个图片片段组成的映射。谢谢你的建议!是否可能是服务器导致了此问题?url变量是否正常?成功函数参数也会丢失xhr参数。你能重构你的代码吗?
document.getElementById(“用户名”)
应该是
document.getElementById(“username”).value
,密码应该是相同的(或者
$(“username”).val()
——为什么不使用jQuery函数?)。转到真正的jQuery而不是缩小的版本(删除文件名的.min),这样我们就可以理解在jQuery中发生这种情况的地方