php - Edit row of table with ajax (no jquery) -
i want change row numbers 1, 2 , 3 number 4, 5 , 6 ajax (no jquery) when push button. how can it? because code can't.
this main .php:
<!doctype html> <html> <head> <title>hola mundo con ajax</title> <script> function loadxmldoc() { var xmlhttp; if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("mydiv").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","carga.php",true); xmlhttp.send(); } </script> </head> <body> <table> <tr> <td bgcolor="#d6d6d6">field 1</td> <td bgcolor="#d6d6d6">field 2</td> <td bgcolor="#d6d6d6">field 3</td> </tr> <tr> <div id="mydiv"><td>1</td> <td>2</td> <td>3</td></div> </tr> </table> <button onclick="loadxmldoc()">cambio</button> </body> </html>
this cargar.php:
<?php echo "<td>4</td> <td>5</td> <td>6</td>"; ?>
try this:
<!doctype html> <html> <head> <title>hola mundo con ajax</title> <script> function loadxmldoc() { var xmlhttp; if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else { // code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("mytable").tbodies[0].innerhtml+=xmlhttp.responsetext; } } xmlhttp.open("get","carga.php",true); xmlhttp.send(); } </script> </head> <body> <table id="mytable"> <tbody> <tr> <td bgcolor="#d6d6d6">field 1</td> <td bgcolor="#d6d6d6">field 2</td> <td bgcolor="#d6d6d6">field 3</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td></div> </tr> </tbody> </table> <button onclick="loadxmldoc()">cambio</button> </body> </html>
Comments
Post a Comment