Initiate the script while the GIF is uploading in the background

I'm looking to achieve a specific effect on my website.

On the main page, I want an image link. When the user clicks on the image, it should disappear and be replaced by a GIF loading bar. Instead of a traditional loading bar, I prefer to use a GIF file for this purpose. Once the script is executed, the GIF should be hidden and a success message displayed.

I do not intend to upload any images; rather, I simply want to run a PHP script while the GIF is shown. I have already conducted extensive research on this topic and haven't found what I'm looking for. Any help would be greatly appreciated. Thank you.

Answer №1

If you're looking to streamline a task on your website, utilizing the jQuery library can be extremely beneficial. While it's possible to achieve the same outcome without jQuery, incorporating it into your workflow can simplify the process significantly.

For instance, consider the following example that mirrors a snippet I frequently employ in my own projects. In this scenario, Script.php represents the server-side script, original.gif pertains to an image displayed on your webpage, and loading.gif serves as the animated 'loading bar' visual.

To implement this code snippet, ensure that you have included the jQuery library within your page.

$(document).ready(function() {
    $('#gifImage').click(gifImage_click);
    // Here, gifImage corresponds to the ID of the image you wish to swap with a loading gif.
});

function gifImage_click() {
    // This code snippet replaces the initial gif image with the loading animation.
    $('#gifImage').attr('src','loading.gif');

    function successFunction(response) {
        // Executed upon successful script execution.
        $('#gifImage').attr('src','original.gif');
        alert('script completed successfully');
    }

    function errorFunction(xhr) {
        // Triggered if the script encounters an error during execution.
        $('#gifImage').attr('src','original.gif');
        alert('script execution failed');
    } 

    $.ajax({
        type: "POST",
        url: "Script.php",
        success: successFunction,
        error: errorFunction
    }); // end - $.ajax
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Execute code if the element is present on the page

I am working with the following javascript: $(document).on('click', '#layer_cart .cross, #layer_cart .continue, .layer_cart_overlay', function(e){ e.preventDefault(); $('.layer_cart_overlay').hide(); $('#laye ...

HTML5 enables the creation of an imperceptible scrollbar

I am looking to make my scrollbar invisible without it being visible however, I still want it to function when hovering over the box Also, I need it to work smoothly on both tablets and computers, which is why I have opted for using html5 I would great ...

Javascript's associative arrays: a versatile tool for data organization

Is there a way to achieve the same functionality in JavaScript as this PHP code?: $this->gridColumnData[] = array('field' => 'id', 'width' => 50, 'title' => 'Enquiry Id') ; $this->gridColumn ...

Can you explain the function of a digest attribute?

As a beginner in the world of NextJS, I am currently working on getting my first project ready for production. However, I encountered the following error: Application error: a client-side exception has occurred (see the browser console for more information ...

Creating an event listener to conceal a popup with a click

One of the key elements in my project is a popup with the unique identifier of myPopup. The class show is responsible for toggling the display property from none to block, allowing the popup to appear on the screen. As a beginner in using event handlers, ...

Creating a spherical shape without relying on SphereGeometry: Is it possible?

I am attempting to create a sphere without utilizing SphereGeometry. My approach involves drawing the sphere using latitudes and longitudes. Below is the code snippet I am working with: for (var phi = -Math.PI / 2; phi < Math.PI / 2; phi += Math.PI / 1 ...

Switch the custom audio control button on and off within a v-for loop

I have implemented a unique audio play/pause button in my Vue app for a list of audios. Here is how it looks: <div v-for="(post, p) in post_list"> ... ... ... <v-avatar v-if="!is_played" color="#663399" ...

Adjust the styling of elements when they are positioned 300 pixels from the top of the viewport

Hey there, I don't have much experience with JavaScript, but I gave it a shot. I managed to create a script that changes the properties of an element based on its position relative to the viewport of the browser. It took me a couple of days to get it ...

Having an issue with HTML and JavaScript where the button won't open when pressed. Any help is appreciated

https://jsbin.com/haluhifuqe/edit?html,js,output I'm facing an issue with my HTML & JavaScript code - when I click the button, it doesn't open. Can anyone help me out? <!DOCTYPE html> <html> <head> <meta charset="utf-8 ...

I'm looking to utilize this script to generate multiple buttons that insert content into a textarea. How can

Finally, I stumbled upon a script that enables undo/redo functionality for programmatically inserted text. You can find it here. If you want to check out the original script demo, click here. Here is the initial script: <div class="snippet" data-lang= ...

Creating a structure object in a Laravel controller for implementing Vue.js autocomplete functionality

I am currently facing an issue with my autocomplete feature not displaying options correctly. To start off, I am fetching hard coded data from my controller and passing it through an axios call: searchController.php $searchResults = [ 0 => (ob ...

Enhance the appearance of specific form inputs upon modification of ng-model within the textfield using AngularJS

After asking a similar question multiple times, I've realized that the specifics of my query were not clear enough. Let's say in my controller there is an object named "guy" of type person structured like this: {"ID" : "1234", "firstNam ...

When utilizing the map function with an array containing 168 objects in the state of a React application, a freeze of around 1

I encountered an issue when trying to update a property in a state array of objects after executing an axios.put request. Here is my code: States - useEffect //... const [volunteers, setVolunteers] = useState([]); //... useEffect(() => { async fu ...

Tips for How to Put a Delay on Ajax Requests and Display a Progress Bar During Loading

I am using checkboxes in the sidebar. When a user selects a checkbox from the sidebar, it displays the post normally. Is there a way to add a progress bar to delay the Ajax result? This is my Ajax code: <script> jQuery(document).ready(function($){ ...

Can Appcelerator Titanium download and execute JavaScript code dynamically?

I'm looking for a straightforward answer to my question. Is it possible to download and interpret JavaScript code for Titanium as a native app at runtime, or does the code need to be compiled within the application? Thanks in advance! ...

I encounter internal server errors when trying to upload images in React

Attempting to send a post request with an image, but encountering errors without understanding why.https://i.sstatic.net/W5uk1.png const [image, setImage] = useState([]); const handleImage = (event) => { setImage(...Array(event.target.files ...

What sets apart the two syntaxes for JavaScript closures?

Similar Query: Is there a distinction between (function() {…}()); and (function() {…})();? I've come across a way to prevent variables from becoming global by using the following syntax: (function ($, undefined) { })(jQuery); Rec ...

Enhance your Javascript code performance by efficiently identifying IDs within a list and linking them to a tree structure

Looking for a way to improve the performance of the logic used for iterating over tree data and applying 'dataState' to 'FAILED' if there are matching error ids. interface IData { id: string; label: string; . value: string; expa ...

what sets apart parseint from minus

Typically, my approach for parsing numbers in JavaScript involves the following code snippet: var x = "99" var xNumber = x - 0 as opposed to using: var xNumber = parseInt(x) I am curious to know if there are any potential issues with this method in ter ...

Step-by-step guide on crafting a scrolling marquee with CSS or Javascript

I am in need of creating two marquees for a website project. The first marquee should showcase a repeating image while the second one should display links, both spanning the browser window at any size. It is crucial that the marquee items are displayed fro ...