我正在嘗試使用ajax將我從jsp中的表中獲取的參數發送到其他JSP。 我用followinf函數來發送所有的值到JSP:給ajaxForm但我不知道爲什麼發送失敗我每次運行它:用ajax發送參數
這裏是JavaScript函數:
function editarow() {
var xhr = getXhr();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
selects = xhr.responseText;
// On se sert de innerHTML pour rajouter les options a la liste
document.getElementById('prjsel').innerHTML = selects;
}
};
var row, firstNameCell, lastNameCell;
var table = document.getElementById("sheet");
var buttons = table.getElementsByTagName("button");
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].name == "edit") {
buttons[i].onclick = function() {
row = this.parentNode.parentNode;
// The first name cell is the first child
NameCell1 = findElement(row.firstChild);
NameCell2 = findElement(NameCell1.nextSibling);
NameCell3 = findElement(NameCell2.nextSibling);
NameCell4 = findElement(NameCell3.nextSibling);
NameCell5 = findElement(NameCell4.nextSibling);
NameCell6 = findElement(NameCell5.nextSibling);
NameCell7 = findElement(NameCell6.nextSibling);
// `innerHTML` pour obtenir la valeur
/*alert("name 1 is " + NameCell1.innerHTML);
alert("name 2 is " + NameCell2.innerHTML);
alert("name 3 is " + NameCell3.innerHTML);
alert("name 4 is " + NameCell4.innerHTML);
alert("name 5 is " + NameCell5.innerHTML);
alert("name 6 is " + NameCell6.innerHTML);
alert("name 7 is " + NameCell7.innerHTML);*/
}
}
}
xhr.open("POST", "ajaxForm.jsp", true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send("NameCell1="+NameCell1,"NameCell2="+NameCell2,"NameCell3="+NameCell3,"NameCell4="+NameCell4,"NameCell5="+NameCell5,"NameCell6="+NameCell6,"NameCell7="+NameCell7);
}
我後從表格中獲取值我想將它們全部發送到ajaxForm.jsp
。