延迟ajax中的xmlHTTPresponse,直到从后端生成结果

时间:2016-04-14 06:04:15

标签: java jquery ajax

我有这个用于ajax的java脚本代码,但我无法获得响应。

xmlhttp.status总是变为0.我有repeatCallHr Servlet并从jsp页面获取参数如下。

function loadResults() {
var tt = document.getElementById("StartDate");
alert(tt);
if (xmlhttp) {
    var query = "generateResults?name="
            + document.getElementById("name").value
            +"&startDate="+document.getElementById("StartDate").value
            +"&startTime="+document.getElementById("StartTime").value;
    xmlhttp.open("GET", query, true);
    xmlhttp.onreadystatechange = loadStallsResponse;
    xmlhttp.send(null);
} else {
    alert("Browser not supported!");
}}

function loadStallsResponse() {
alert("come here");
alert(xmlhttp.readyState);
if (xmlhttp.readyState == 4) {
    alert("status is :"+xmlhttp.status);
    if (xmlhttp.status == 200) {
        resultList = [];
        if (xmlhttp.responseText.indexOf("Error") == -1) {
            alert("come to inside of status::")
            console.log(xmlhttp.responseText);
            stallList = $.parseJSON(xmlhttp.responseText);
            populateStallData();
        } else {
            alert(xmlhttp.responseText);
        }
    } else {
        alert("Error in loading salesman data");
    }
}}

function populateStallData() {
var table = "<tr><th>Date</th><th>Time</th><th>Skill</th><th>Total Call</th><th>Unique Calls</th><th>Repeat Calls</th></tr>";
for (var i = 0; i < resultList.length; i++) {
    table += "</td><td width='140'>"
            + resultList[i].date
            + "</td><td width='140'>"
            + resultList[i].time
            + "</td><td width='140'>"
            + resultList[i].skill
            + "</td><td width='140'><a style='color: -webkit-link; text-decoration: underline; cursor: auto;' href='http://"
            + resultList[i].totalCall
            + "</td><td width='140'>"
            + resultList[i].uniqueCall
            + "</td><td width='140'>"
            + resultList[i].repeatCall
            + "</td></tr>";
}
document.getElementById("ResultTable").innerHTML = table;}

在后端,查询sql语句需要5分钟以上,以便xmlhttp.status返回0(我猜,但我不确定)。如何在后端生成结果之前延迟xmlhttp响应时间?

0 个答案:

没有答案