0

I have a JQUERY function that uses AJAX via a PHP page, when the AJAX is running I have a loading.gif show for the user. When the AJAX returns the json data that was requested all is fine. What I would like to do would be to make any user input null while this is happening.

What would be the best way to go about this?

EDIT:

I ended up using...

$('#loadingDiv')
    .hide()  // hide it initially
    .ajaxStart(function() {
        $(this).show();
    })
    .ajaxStop(function() {
        $(this).hide();
    })
;

From the post How to show loading spinner in jQuery?

Thanks for the suggestions!

Community
  • 1
  • 1
Monty
  • 1,254
  • 4
  • 18
  • 34

3 Answers3

2

Just as an interesting idea.

This is somewhat a dirty hack but you can disable any keyboard input within your website during Ajax requests by adding this event to $(document).ready:

​$(document).on("keydown", function(e) {
    return $.active == 0;
});​​​​​​​​​​​​​​

It works like that: $.active returns the number of active Ajax requests. If it is 0 then any keydown will be returned as false.

VisioN
  • 132,029
  • 27
  • 254
  • 262
1

You can:

  • Gray the screen with a spinner until the request succeed (the loading.gif)
  • Disable the input field by setting disabled=disabled

See this question:How to show loading spinner in jQuery? and jQuery .ajaxStart()

Community
  • 1
  • 1
noirbizarre
  • 3,199
  • 1
  • 27
  • 21
0

Just disable the fields as said by xbonez. Make sure to give your users a feedback about what is keeping them from entering data. Otherwise they will think your app just freezed.

Tulio F.
  • 994
  • 15
  • 27