---
title: "Loading image not working"  
description: "Loading image not working"  
author: "Sumit Kesarwani"  
published: 2014-09-20  
updated: 2014-09-24  
canonical: https://www.mindstick.com/forum/2258/loading-image-not-working  
category: "asp.net mvc"  
tags: [".net", "asp.net mvc"]  
reading_time: 2 minutes  

---

# Loading image not working

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to display the loading [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) when the [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) is processing.

It [actually works](https://answers.mindstick.com/qa/116034/how-the-dark-web-actually-works) fine when I haven't made any [mistakes](https://www.mindstick.com/articles/12952/the-8-major-mistakes-players-make-in-the-casinos) when [filling](https://yourviews.mindstick.com/audio/1303/the-power-of-silence-what-happens-when-you-stop-filling-every-moment) the form, but when I miss a [required](https://www.mindstick.com/forum/160269/what-is-required-data-annotation-how-does-it-affect-model-validation) field

for example, the loading image pops up and it doesn't go away and the [validation](https://www.mindstick.com/articles/12234/validation-using-data-annotation-using-entity-framework) of the field is made.

**I've tried to use jQuery to do something like this:**

```
    $(function () {   
$("#button").click(function () {   
alert(form.valid());    if (form.valid())
{       
$("#divLoading").show();        $.post({            type:'POST',            url: url,            data:data,            success:
function (data) {               
$("#divLoading").hide();            }        });    } else {       
alert("Not valid.");    }    //}});});
```

So, when I ask if the form is valid it returns true, in spite of leaving a required [field blank](https://www.mindstick.com/forum/34414/how-to-add-focus-to-a-field-when-the-user-leaves-the-field-blank-in-my-form).

## My model is the following:

```
    public class MotivoDTO    {        public MotivoDTO()        {        }       
[Required(ErrorMessage = "You must enter a Motive.")]       
[DataType(DataType.Text)]        [Display(Name= "Descripcion")]        public string Descripcion { get; set; }     }
```

Thank you!

## Replies

### Reply by Anonymous User

thanks

### Reply by Sumit Kesarwani

$.post({

type: 'POST',

url: url,

data: data,

success: function (data) {

$("#divLoading").hide();

}

}).always(function() { $("#divLoading").hide(); });

\

### Reply by Anonymous User

Update your .ajax() call to make use of the different events available to you inside of the ajax() function.

$(function () {

$("#button").click(function () {

alert(form.valid());

if (form.valid()) {

$.post({

type: 'POST',

url: url,

data: data,

//do this before you start the POST method

beforeSend: function(){

$("#divLoading").show();

},

//do this regardless if it was successful or not

complete: function (data) {

$("#divLoading").hide();

}

});

} else {

alert("Not valid.");

}

}

### Reply by Anonymous User

try this:\
\

form.validate();

if (form.valid()) {

\


---

Original Source: https://www.mindstick.com/forum/2258/loading-image-not-working

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
