移动设备上的 AJAX 请求不起作用

AJAX Request on Mobile Devices NOT Working

本文关键字:AJAX 请求 不起作用 移动      更新时间:2023-09-26

我在使 AJAX 在移动设备上运行时遇到问题,我有一个简单的支持票证网站......我可以从服务器获得异步响应...

请求已发出,但我没有得到响应

我在带有Android 4.0.3的表格和带有4.1.2的索尼Xperi中进行测试

页面加载,但不处理 Javascript 异步请求

这是我的代码:

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();
}

您需要使用提供服务的服务器的 URL。如果您使用的是托管服务,它将是您的域名。如果您使用的是本地服务器,它将是您在本地 DNS 中为其分配的任何名称,假设您的移动设备具有 Wifi 连接。如果他们使用3G或GPRS,那么事情就会变得更加复杂。