jqueryajaxjquery-blockui

Error in attempt to blockui (and unblockui) on ajaxStart/Complete


This is my first project and I am attempting to have the blockui fire when the application hits up the server for information. I looked up a few examples and thought my attempt below would work, but I was wrong.

        $(document).ajaxStart(function(){
        $.blockUI({
            css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
            }
        });


        $(document).ajaxComplete(function(){
            $.unblockUI()
        });

Solution

  • If this is your full code, you forgot a }); for the $(document).ajaxStart(function(){ handler:

    $(document).ajaxStart(function(){
        $.blockUI({
            css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
            }
        });
    });   // <----- HERE
    
    
    $(document).ajaxComplete(function(){
        $.unblockUI()
    });