Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wholeomarfaruk/ajax-multipart-formdata-passing-with-jquery

This project demonstrates how to use jQuery to handle form submissions with multipart FormData, including file uploads, via Ajax. It includes a sample HTML form, a JavaScript file for Ajax handling, and a PHP backend for processing the submitted data.
https://github.com/wholeomarfaruk/ajax-multipart-formdata-passing-with-jquery

ajax ajax-multipart-formdata-passing-with-jquery ajax-requests api-integration asynchronous client-server-communication data-transmission dynamic-forms file-data-passing-with-ajax file-upload form-handling formdata formdata-serialize front-end javascript jquery multipart web-development

Last synced: about 1 month ago
JSON representation

This project demonstrates how to use jQuery to handle form submissions with multipart FormData, including file uploads, via Ajax. It includes a sample HTML form, a JavaScript file for Ajax handling, and a PHP backend for processing the submitted data.

Awesome Lists containing this project

README

        

# Ajax Multipart FormData Passing with jQuery

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.

## Project Structure

- `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.

## Setup and Usage

### Prerequisites

- A web server with PHP support (e.g., XAMPP, WAMP, MAMP).
- Internet connection for loading external dependencies (Bootstrap, jQuery).

### Instructions

1. **Clone the repository**:
```bash
git clone https://github.com/wholeomarfaruk/ajax-multipart-formdata-passing-with-jquery.git
```

2. **Navigate to the project directory**:
```bash
cd ajax-multipart-formdata-passing-with-jquery
```

3. **Start your local web server** and place the project directory in the server's root directory (e.g., `htdocs` for XAMPP).

4. **Open `index.html` in your web browser**:
```plaintext
http://localhost/ajax-multipart-formdata-passing-with-jquery/index.html
```

5. **Fill out the form** and submit. You can inspect the response in your browser's developer console or network tab.

### File Descriptions

- **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).

### Key Features

- **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.

### Dependencies

- **Bootstrap**: Included via CDN.
- **jQuery**: Included via CDN.

### Example Usage

1. **Fill out the form**:
- Enter text data in the respective fields.
- Upload a file using the file input.

2. **Submit the form**:
- The form data and file will be sent to `backend.php` for processing.

3. **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.

## License

This project is open-source and available under the [MIT License](LICENSE).

## Keywords

- 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