javascript - Pass HTML table row to PHP via AJAX using POST -
i have page html table containing results query. next each row, have button that, when clicked, make lightbox appears small html form user can enter comment.
when user clicks submit button on form, should send data contained in row (ie, each cell value array if that's possible) comment script, insert them in database.
after done, small message saying appears, , user can go table lightbox disappears.
my problem transmitting data php script process it. ajax javascript works alright, except don't know how send data.
here code :
function getoutput() { //get number of selected table row var = document.getelementbyid('rowclicked').value; //get table var table = document.getelementbyid('table'); //get comment var comm = document.getelementbyid('comment').value; var ajax = getrequest(); ajax.onreadystatechange = function(){ if(ajax.readystate == 4){ alert(ajax.responsetext); } } ajax.open("post", "functions_comm.php", true); ajax.setrequestheader('content-type', 'application/x-www-form-urlencoded'); //only try send table row ajax.send(table.rows[i]); }
if put "php echo "test"; " in "functions_comm.php", "alert(ajax.responsetext);" displays "test", part working. however, if try "print_r($_post)", returns empty array, assume means no data passed "ajax.send(table.rows[i]);".
how can pass data row of table php script ?
thanks.
- you can't send instance of domelement. can send string, if want send text of element, use innerhtml property.
- the message body should url-encoded (when sending application/x-www-form-urlencoded).
ajax.send("tabledata=" + encodeuri(table.rows[i].innerhtml));
Comments
Post a Comment