Skip to main content

Posts

Showing posts with the label ajax

How to upload file using Ajax and php

Let me guide you through adding AJAX file upload functionality to your website. For this purpose, you'll need to use JavaScript to handle the AJAX request and interact with the server. In this example, I'll show you how to implement a basic file upload using AJAX and PHP on the server side. HTML File (index.html) : Create an HTML form with a file input and a button to trigger the upload process. Add a ' <div>' to display the upload status. File Upload Example File Upload Example Upload 2. JavaScript File (upload.js): Create a JavaScript file to handle the AJAX request when the "Upload" button is clicked. document.addEventListener("DOMContentLoaded", function () { const uploadButton = document.getElementById("upload-button"); const fileInput = document.getElementById("file-input"); const uploadStatus = document.getElementById("up...

How do i make API request in Ajax

Creating API request using Ajax is easy and great way to get data from API. Here's an example of how you can create an AJAX (Asynchronous JavaScript and XML) API request using the jQuery library. For help contact here . This example demonstrates how to make a GET request to an API endpoint: $(document).ready(function() { // Define the API endpoint URL var apiUrl = "https://api.example.com/data"; // Make the AJAX GET request $.ajax({ url: apiUrl, type: "GET", dataType: "json", // Change to the appropriate data type success: function(data) { // Process the response data $("#result").html(JSON.stringify(data)); }, error: function(xhr, status, error) { // Handle error cases console.error("Error:", error); } }); }); In this example: Include the jQuery library from a CDN within the <head> section of your H...