Answers for "how to submit form data using ajax jquery"

15

jQuery AJAX form submit

// jQuery ajax form submit example, runs when form is submitted
$("#myFormID").submit(function(e) {
    e.preventDefault(); // prevent actual form submit
    var form = $(this);
    var url = form.attr('action'); //get submit url [replace url here if desired]
    $.ajax({
         type: "POST",
         url: url,
         data: form.serialize(), // serializes form input
         success: function(data){
             console.log(data);
         }
    });
});
Posted by: Guest on July-25-2019
-1

Submit AJAX Forms with JQuery to database

// Database Structure 
CREATE TABLE `contacts` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` text NOT NULL,
 `email` text NOT NULL,
 `reason` text NOT NULL,
 `message` text NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1

<?php
if(isset($_POST['submit_contact']))
{
 $name=$_POST['name'];
 $email=$_POST['email'];
 $reason=$_POST['reason'];
 $message=$_POST['message'];
	
 $host="localhost";
 $username="root";
 $password="";
 $databasename="sample";
 $connect=mysql_connect($host,$username,$password);
 $db=mysql_select_db($databasename);
 
 mysql_query("insert into contacts values('','$name','$email','$reason','$message')");
 echo "submitted";
 exit();
}
?>
Posted by: Guest on April-09-2021

Code answers related to "how to submit form data using ajax jquery"

Code answers related to "Javascript"

Browse Popular Code Answers by Language