Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm polling my server using jQuery's ajax function and then using that data to update a canvas. I poll the server once each second (this is not done using setInterval(), in case you're wondering... I did hear that is sometimes the source of these issues. The canvas is animated, and I keep track of the frame rate. I use this data to figure out when a second has elapsed). This isn't an issue in Chrome, but in Firefox and Maxthon Cloud (and to a MUCH MUCH lesser degree Opera), performance gradually grows worse and worse. I think it's the ajax calls, and I have NO IDEA how to fix the issue. Here is my "callServer()" function, if that's of any use. Thanks!

function callServer(action, json)
{
    if(!json)
    {
        $.ajax({
            type: 'POST',
            url: 'okey.php.',
            data: 'action=' + action,
            cache: false,
            success: function(data)
            {
                switch(action)
                {
                    case 'ptv':
                        tilesValue = data;
                        break;
                    case 'ptc':
                        tilesColor = data;
                        break;
                    case 'tid':
                        //alert(data);
                        thisPlayerID = data;
                        break;
                    case 'pti':
                        playerTurnInfo = data;
                        //alert(data);
                        break;
                    case 'gs':
                        gameStatus = data;
                        break;
                    case 'steal':
                        alert(data);
                        break;
                    case 'draw':
                        alert(data);
                        break;
                    case 'testing':
                        alert(data);
                        break;
                }
            }
        });
    }
    else if(json)
    {
        $.ajax({
            type: 'POST',
            url: 'okey.php.',
            data: 'action=' + action,
            dataType: 'json',
            cache: false,
            success: function(data)
            {
                switch(action)
                {
                    case 'ptv':
                        tilesValue = data;
                        break;
                    case 'ptc':
                        tilesColor = data;
                        //alert(tilesColor.length);
                        break;
                    case 'pn':
                        playerNames = data;
                        break;
                    case 'pid':
                        playerIDs = data;
                        break;
                    case 'pts':
                        //alert("excellent");
                        turnStatuses = data;
                        break;
                    case 'ti':
                        tileIndeces = data;
                        //alert(tileIndeces.length)
                        break;
                    case 'dis':
                        //alert(parseInt(data[3]));
                        discarded = data;
                        //alert(parseInt(discarded[3]));
                        break;
                }
            }
        });
    }
}

Update: It is not the frequency of the calls that is causing the issue.

share|improve this question
As a suggestion - you don't need if (!json) and then else if (json) - you could just make the else if (json) be else. Also, you're going to have to show how you're calling this code. – Ian 2 days ago
1  
The $.ajax by default perform an asynchronous request. Maybe firefox cant handle request as fast and Chrome does and keep stacking the requesting. Try to set the request to sync to see how it does. BTW, since you are getting data constantly, have you though about using WebSockets? – wendelbsilva 2 days ago
I just say "callServer('steal', false);" Also, I have tried making the requests synchronously, but that just causes more problems. I have considered web sockets, but I have no familiarity with them. I will try making the requests less frequently and seeing if that helps. With regard to the ifs, that's true. The clunky coding is just a vestige of the fact that there used to be more options. – user2529036 2 days ago

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.