javascriptajaxasynchronous

AJAX Request on Mobile Devices NOT Working


I have a problem making AJAX work on mobile devices, I have a simple site for Support Tickets; I CAN'T get the Async response from the server.

The request is made, but I don't get the response.

I'm testing in a table with Android 4.0.3 and in my Sony Xperi with 4.1.2.

The page loads but it doesn't process the JavaScript Async Requests

This is my code:

function ajaxAsyncRequest(htmlEntityTarget, progressTarget, requestKey, queryId) {
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
        document.getElementById(progressTarget).innerHTML = "Processing Request...";
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {            
            
            switch(requestKey) {
                case "loadTickets":
                    document.getElementById(htmlEntityTarget).innerHTML = xmlhttp.responseText;                                        
                    document.getElementById(progressTarget).innerHTML = "Done Processing! Tickets Loaded!";
                    break;
                case "loadTicketConversation":
                    document.getElementById(htmlEntityTarget).innerHTML = xmlhttp.responseText;                                        
                    document.getElementById(progressTarget).innerHTML = "Done Processing! Conversations Loaded!";
                    break;
                default:
                    document.getElementById(htmlEntityTarget).innerHTML = "failed response";
                    break;
            }
            
        }
        
    }

    xmlhttp.open("GET", "http://localhost/helpdesk/main/serverRouting/serverRoutingEntryPoint.php?key=" + requestKey + "&&queryId=" + queryId, true);
    xmlhttp.send();
}

Solution

  • You need to use a URL of the server that provides the service. If you're using a hosted service it will be your domain name. If you're using a local server it will be whatever name you have assigned it in your local DNS, assuming your mobile devices have Wifi connection. If they're using 3G or GPRS then things become more complicated.