John Smith John Smith - 1 year ago 67
Javascript Question

JQuery Ajax send data from form not working

My script should prevent the page to be refreshed or redirected, but when i click submit button it redirects me.

Error Message from JavaScript console

Uncaught TypeError: $(...).val(...).len is not a function


$( document ).ready(function() {
console.log( "Ready!" );
//Submitting the form data
if($('#fName').val().len() != "" && $('#lName').val().len() != "" && $('#nickname').val().len() != "") {
type: "POST",
url: "user-process.php",
data: $("#user-form").serialize(),
success: function(data){
console.log(data); // show response from the php script.
else {
alert("Please fill the fields.")

setInterval(function(){ $(`#table`).load('info.php #table'); }, 1000); //Loading table data without refreshing page.


Answer Source

"len()" is not a javascript function, you can modify your code to be :

if( $('#fName').val() && $('#lName').val() && $('#nickname').val() )

and will work

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download