代碼如下,仔細看能看懂,用了一點RE的內容。js中,用//括起來的字串表示是一個RE字串。
function updateStuffs() {
var response;
if (request.readyState == 4) {
if (request.status == 200) {
response = request.responseText;
var content_array = response.split("==== DELIMITER ====");
var peselect = document.getElementById("peselectid");
var prjselect = document.getElementById("prjselectid");
var masterqselect = document.getElementById("masterqselectid");
var ls = /^\s*/; // Leading space regular expression
var ts = /\s*$/; // Trailing space regular expression
// Break the response into lines
var lines = content_array[0].split("\n");
var peselect_result = "";
// Loop through the lines
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.length == 0) continue; // Skip empty lines
line = line.replace(ls, "").replace(ts, "");
if (line.length == 0) continue; // Skip space filling lines
peselect_result += line + "\n";
}
// Break the response into lines
lines = content_array[1].split("\n");
var prjselect_result = "";
// Loop through the lines
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.length == 0) continue; // Skip empty lines
line = line.replace(ls, "").replace(ts, "");
if (line.length == 0) continue; // Skip space filling lines
prjselect_result += line + "\n";
}
// Break the response into lines
lines = content_array[1].split("\n");
var masterq_select_result = "";
// Loop through the lines
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.length == 0) continue; // Skip empty lines
line = line.replace(ls, "").replace(ts, "");
if (line.length == 0) continue; // Skip space filling lines
masterq_select_result += line + "\n";
}
peselect.innerHTML = "<select name='pe_name' class='listselect'>" + peselect_result + "</select>";
prjselect.innerHTML = "<select name='project' class='listselect'>" + prjselect_result + "</select>";
masterqselect.innerHTML = "<select name='master_queue' class='listselect'>" + masterq_select_result + "</select>";
} else if (request.status == 404) {
alert("<bean:message key='error.ajax.urlnotexist'/>");
} else {
alert("<bean:message key='error.ajax.errorcode'/>" + request.status);
}
}
}