0

I am new in JavaScript, ِ All I need is to add a loading image (gif) to the following script when the form is submitted without errors.

I use the code with a script available on internet (Facebook-like Registration Form with jQuery).

Any help please?

$(document).ready(function () {
    $('#regForm').submit(function (e) {
        register();
        e.preventDefault();
    });
});

function register() {
    hideshow('loading', 1);
    error(0);
    $.ajax({
        type: "POST",
        url: "submit.php",
        data: $('#regForm').serialize(),
        dataType: "json",
        success: function (msg) {
            if (parseInt(msg.status) == 1) {
                window.location = msg.txt;
            } else if (parseInt(msg.status) == 0) {
                error(1, msg.txt);
            }
            hideshow('loading', 0);
        }
    });
}

function hideshow(el, act) {
    if (act) $('#' + el).css('visibility', 'visible');
    else $('#' + el).css('visibility', 'hidden');
}

function error(act, txt) {
    hideshow('error', act);
    if (txt) $('#error').html(txt);
}

1 Answer 1

1

you need 2 elements, something in your html like

<img src="loading.gif" id="loading" style="visibility:hidden"> 

(will show with hideshow('loading',1) and hide again when the server responds. Also another one

<img src="error.gif" id="error" style="visibility:hidden"> 

for the error. Of course loading.gif and error.gif could be any valid image file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.