Ajax delay simulation

I have a small ajax jquery script that returns XML to me. While it works and communicates with the server, I show the animation of the bootloader.

The problem is that I do not see the animation. Either I did something wrong, or the network connection is really fast.

Does anyone know how I can imagine a delay for my ajax code to slow down the process and I can check the animation function?

Thank.

ps: given ajax code, just incase

function fetchData($nodeid, $area){
    if( $nodeid != $currentRoomId ){
        popupBox($area);//$area, $roomInfo);
    }

        var $nid, $title, $classroom, $boardroom, $cabaret;
        $.ajax({

            url: "/room/" + $nodeid + "/rss.xml",
            dataType: "xml",
            success: function($xml){

                $returnXML  =   $xml;
                $($xml).find('node > *').each(
                    function(){

                        switch( $(this).attr('name') ){
                            case 'Nid':
                                $nid    =   $(this).text();
                            break;
                            case 'Title':
                                $title  =   $(this).text();
                            break;
                            case 'Classroom':
                                $classroom  =   $(this).text();
                            break;
                            case 'Boardroom':
                                $boardroom  =   $(this).text();
                            break;
                            case 'Cabaret':
                                $cabaret    =   $(this).text();
                            break;
                            case 'Theatre':
                                $theatre    =   $(this).text();
                            break;
                            case 'Notes':
                                $notes  =   $(this).text();
                            break;
                            default:
                            break;
                        }//close switch statement
                    }
                );
                $roomInfo   =   new Array();
                $roomInfo.push('Title', $title);
                $roomInfo.push('Classroom', $classroom);
                $roomInfo.push('Boardroom', $boardroom);
                $roomInfo.push('Cabaret', $cabaret);
                $roomInfo.push('Theatre', $theatre);
                $roomInfo.push('Notes', $notes);
                highlightRow($nid);
                popupBox($area, $roomInfo);
            },
            statusCode: {
                200: function(){
                    //alert('responding just fine!');
                }
            },
            error: function(){
                //alert('Ajax not responding!');
            },
            complete: function(){
                //alert('completed!');
            }
        });
    }
+3
source share
3 answers

A quick fix is ​​to move your ajax call inside the if block. By success / error - hide the animation. This will not simulate a delay, but it will ensure that your animation is displayed (even if for ms).

0
source
+2

If you have control over your server code, you can force the server to delay the AJAX response by adding a delay to the server code, instead of causing a delay in the client.

+1
source

All Articles