我有这个用于ajax的java脚本代码,但我无法获得响应。
xmlhttp.status总是变为0.我有repeatCallHr Servlet并从jsp页面获取参数如下。
function loadResults() {
var tt = document.getElementById("StartDate");
alert(tt);
if (xmlhttp) {
var query = "repeatCallHr?skill="
+ document.getElementById("ServiceCode").value
+"&startDate="+document.getElementById("StartDate").value
+"&startTime="+document.getElementById("StartTime").value
+"&endDate="+document.getElementById("EndDate").value
+"&endTime="+document.getElementById("EndTime").value;
xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange = loadStallsResponse;
xmlhttp.send(null);
} else {
alert("Browser not supported!");
}}
在下面的代码中,我正在调用AJAX请求并尝试从中获取响应。
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;}
但它将xmlhttp.status设为0.请帮我弄清问题是什么。