This simple lesson will show how to use the Jquery serialize() function to pass all form data to an ajax file. With the serialize() function, it is very easy to pass all form data name and values to the ajax file without having to send them all separately.
I will go over this in detail. When the user inputs a name in the text input box and clicks 'Submit it', the Jquery .submit() method is triggered. We pass in the e into the function and use e.preventDefault() method too because you do not want the usual form submission to happen....which would be a typical post request that would reload the page.
After that, the formData variable is created and it contains the names and values from the form. Then, it is passes into Ajax for which it is sent to the ajax_1.php file.
After it arrives to the ajax_1.php file, the parse_str() function is used to make an array from that serialized data. In that array, is the first name that was entered into the text field. Thus, the value of that posted test becomes $myArray['myFirst']. Remember that myFirst was the name of the input text box.
After that, it is pretty much a simple mySQL query that finds all users with that first name. Finally, the names are printed in two separate 'div' elements. Note that the printed text in the ajax file is handled as the msg variable in the original file.
The code below is represents the ajax_1.php which handles the data made from the original page. The code is very limited and although it shows how to handle the data, any production server would need a layer of security built around it so unauthenticated users and web robots would be unable to cause damage.