Ajax request problem-Maximum call stack size exceeded
Good afternoon,
I have this simple code below using js but it returns me the error that is in the print below:
Note: I am using CodeIgniter 3.0.10, AJAXm jQuery 3.0.0 Minifed and Bootstrap 4
* * Code: *
jQuery(document).ready(function() {
var base = $("#base_url").val();
$('#telefone').mask('(99) 99999-9999');
jQuery("#form-registrar-estilo").submit(function(e) {
e.preventDefault();
var email_validar = $("#email").val();
for (let el of jQuery('#form-registrar-estilo input')) {
if (el.value == "") el.classList.add("error");
else el.classList.remove("error");
}
if (!jQuery('#form-registrar-estilo input.error').length) {
jQuery.ajax({
url: base + "painel/cadastrar/valida_email",
type: "POST",
data: {email:email},
dataType: "json",
success: function(data) {
alert(data);
}
})
};
});
});
0
Author: Matheus Lopes, 2019-02-17
1 answers
The error is in the value of Ajax's data:
:
data: {email:email},
Should be:
data: {email:email_validar},
When using the variable email
as the value of the argument email:
, you are selecting the input element with the id#email
instead of the value of the field, and with this causing an error in jQuery when dealing with the data:
, since email
, if not declared before, is a global variable referring to the element with id
of the same name.
1
Author: Sam, 2019-02-17 21:17:30