开发者问题收集

未捕获的 RangeError:jquery ajax 调用中超出最大调用堆栈大小

2020-12-21
1133

我遇到了 jQuery ajax 调用的问题。如果我注释掉 ajax 调用,它就可以正常工作。它通过了所有验证,并转到其他具有 ajax 调用的位置。如果我通过注释 ajax 调用来发出一些警报,它就可以正常工作并显示警报。

控制台中的错误:未捕获的 RangeError:超出最大调用堆栈大小。

function submit() {
  var companyname = $('#companyname').val();
  var fname = $('#fname').val();
  var username = $('#email').val();
  var countrycode = $('#country-code').val();
  var mobile = $('#mobile').val();
  var captcha = $('#captcha').val();
  var countryid = $('#country-list').val();
  var ctype = $('#ctype').val();
  console.log(companyname);
  console.log(fname);
  console.log(username);
  console.log(countrycode);
  console.log(mobile);
  console.log(captcha);
  console.log(countryid);
  console.log(ctype);
  if(companyname == '') {
    Swal.fire({
          title: 'Enter Company Name',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(fname == '') {
    Swal.fire({
          title: 'Enter Admin Name',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(username == '') {
    Swal.fire({
          title: 'Enter Admin Email',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(countrycode == '') {
    Swal.fire({
          title: 'Select Country Code',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(mobile == '') {
    Swal.fire({
          title: 'Enter Admin Mobile',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(captcha == '') {
    Swal.fire({
          title: 'Enter Captcha',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(countryid == '') {
    Swal.fire({
          title: 'Select Country',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else {
      $.ajax({
        type: "POST",
        url: "<?php echo base_url(); ?>Home/createcsoorpartner_submit",
        data: {
          companyname: companyname,
          fname: fname,
          countryid: countryid,
          mobile: mobile,
          email: email,
          countrycode: countrycode,
          captcha: captcha,
          ctype: ctype,
        },
        success: function (data) {
          resultObj = $.parseJSON(data);
          console.log(resultObj);
          if(resultObj.result == "success") {
            Swal.fire({
              title: resultObj.msg,
              width: 500,
              padding: '1em',
              background: '#fff',
              backdrop: `
                rgba(0,0,123,0.4)
                left top
                no-repeat
              `
            }).then(function (result) {
                    if (result.value) {
                      window.location = "<?php //echo base_url(); ?>Home";
                    }
                  })
          } else {
            Swal.fire({
              title: resultObj.msg,
              width: 500,
              padding: '1em',
              background: '#fff',
              backdrop: `
                rgba(0,0,123,0.4)
                left top
                no-repeat
              `
            })
          } 
        }
  })(1);
  }
}
2个回答

你得到的错误是 $.ajax 在你试图传递一个包含 循环引用 的结构时产生的错误。

如果数据定义类型不正确,数据无法成功发送到后台。后台收不到数据,前端会一直发送,这种循环会导致堆栈溢出。

所以你要做的就是检查你在ajax中发送的参数是否正确。

Mr Khan
2020-12-21
function submit() {
  var companyname = $('#companyname').val();
  var fname = $('#fname').val();
  var username = $('#email').val();
  var countrycode = $('#country-code').val();
  var mobile = $('#mobile').val();
  var captcha = $('#captcha').val();
  var countryid = $('#country-list').val();
  var userrole = $('#ctype').val();
  
  if(companyname == '') {
    Swal.fire({
          title: 'Enter Company Name',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(fname == '') {
    Swal.fire({
          title: 'Enter Admin Name',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(username == '') {
    Swal.fire({
          title: 'Enter Admin Email',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(countrycode == '') {
    Swal.fire({
          title: 'Select Country Code',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(mobile == '') {
    Swal.fire({
          title: 'Enter Admin Mobile',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(captcha == '') {
    Swal.fire({
          title: 'Enter Captcha',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else if(countryid == '') {
    Swal.fire({
          title: 'Select Country',
          width: 500,
          padding: '1em',
          background: '#fff',
          backdrop: `
            rgba(0,0,123,0.4)
            left top
            no-repeat
          `
        })
  } else {
    console.log(companyname);
  console.log(fname);
  console.log(username);
  console.log(countrycode);
  console.log(mobile);
  console.log(captcha);
  console.log(countryid);
  console.log(userrole);
      $.ajax({
        type: "POST",
        url: "<?php echo base_url(); ?>Home/createcsoorpartner_submit",
        data: {
          companyname: companyname,
          fname: fname,
          countryid: countryid,
          mobile: mobile,
          email: username,
          countrycode: countrycode,
          userrole: userrole,
          captcha: captcha,
        },
        success: function (data) {
          var resultObj = $.parseJSON(data);
          console.log(resultObj);
          if(resultObj.result == "success") {
            Swal.fire({
              title: resultObj.msg,
              width: 500,
              padding: '1em',
              background: '#fff',
              backdrop: `
                rgba(0,0,123,0.4)
                left top
                no-repeat
              `
            }).then(function (result) {
                    if (result.value) {
                      window.location = "<?php //echo base_url(); ?>Home";
                    }
                  })
          } else {
            Swal.fire({
              title: resultObj.msg,
              width: 500,
              padding: '1em',
              background: '#fff',
              backdrop: `
                rgba(0,0,123,0.4)
                left top
                no-repeat
              `
            })
          } 
        }
  });
  }
}
Nazeer Shaik
2020-12-21