This project demonstrates how to prepare and pass form data, including file uploads, using jQuery's $.ajax()
method. The form data is sent to a PHP backend for processing.
index.html
: The main HTML file containing the form.script.js
: The JavaScript file that handles the form submission using jQuery and Ajax.backend.php
: The PHP script that processes the incoming form data and files.
- A web server with PHP support (e.g., XAMPP, WAMP, MAMP).
- Internet connection for loading external dependencies (Bootstrap, jQuery).
-
Clone the repository:
git clone https://github.com/wholeomarfaruk/ajax-multipart-formdata-passing-with-jquery.git
-
Navigate to the project directory:
cd ajax-multipart-formdata-passing-with-jquery
-
Start your local web server and place the project directory in the server's root directory (e.g.,
htdocs
for XAMPP). -
Open
index.html
in your web browser:http://localhost/ajax-multipart-formdata-passing-with-jquery/index.html
-
Fill out the form and submit. You can inspect the response in your browser's developer console or network tab.
-
index.html:
- Contains a form with fields for Full Name, Shop Name, Phone Number, Email Address, Shop Address, Profile Image, and Verify PIN.
- Uses Bootstrap for styling.
-
script.js:
- Handles form submission using jQuery.
- Collects form data and files, packages them into a FormData object.
- Sends the FormData object to the backend PHP script using an Ajax POST request.
-
backend.php:
- Receives and processes the form data and files.
- Prints the received data to the response (for debugging purposes).
-
Form Handling:
- Prevents default form submission behavior.
- Uses
FormData
to handle both text data and file uploads. - Uses
$.ajax()
for asynchronous data submission.
-
Bootstrap Integration:
- Provides a responsive and modern UI for the form.
- Bootstrap: Included via CDN.
- jQuery: Included via CDN.
-
Fill out the form:
- Enter text data in the respective fields.
- Upload a file using the file input.
-
Submit the form:
- The form data and file will be sent to
backend.php
for processing.
- The form data and file will be sent to
-
Check the response:
- Open your browser's developer tools (F12).
- Go to the Network tab and inspect the
backend.php
response. - Alternatively, check the Console for the response logged by the success callback.
This project is open-source and available under the MIT License.
- Ajax
- jQuery
- FormData
- Multipart
- File Upload
- Asynchronous
- JavaScript
- AJAX Requests
- Web Development
- Front-end
- Dynamic Forms
- API Integration
- Form Handling
- Data Transmission
- Client-Server Communication