sending parameters with ajax

Posted by kawtousse on Stack Overflow See other posts from Stack Overflow or by kawtousse
Published on 2010-05-24T10:33:56Z Indexed on 2010/05/24 12:11 UTC
Read the original article Hit count: 344

Filed under:
|
|
|

I am trying to send parameters that I get from a table in my jsp to other JSP using ajax. I am using the followinf function to send all values to JSP: ajaxForm but I don't know why the send failed every time I run it:

Here is the javascript function:

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

After I get the value from the table I want to send all of them to the ajaxForm.jsp.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html