Submit an ajax form created by an ajax call
Three pages Test5.php
<html> <head> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } fst = document.form1.first.value ; sec = document.form1.second.value ; params = "first=" + encodeURI(fst) + "&second=" + encodeURI(sec) ; xmlhttp.open("POST","testproc2.php",true) ; xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded") ; xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } function changeInnerDiv() { alert("In changeInnerDiv") ; var xmlhttp ; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } fst = document.form1.first.value ; sec = document.form1.second.value ; params = "first=" + encodeURI(fst) + "&second=" + encodeURI(sec) ; xmlhttp.open("POST","testproc3.php",true) ; xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded") ; xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); } </head> <body> This text should remain static
<hr> <div id="myDiv"> <?php echo "<form name="form1"> " ; echo "First: <input type="text" name="first">
" ; echo "Second: <input type="text" name="second">
" ; echo " </form> " ; ?> <button type="button" onclick="loadXMLDoc()">Change Content</button> </div> </body> </html>
Pressing the button calls page testproc2.php as expected, it does echo the two values from the form
<html> <head> </head> <body>But nothing happens when I press the submit on testproc2.php. I've tried putting a div in testproc2.php, tried moving the java script into testproc2.php. Submit does nothing. Is it possible to have an ajax call return a form that can be submitted? I'd rather not, but do I need jquery? Thanks Brian 链接地址: http://www.djcxy.com/p/22330.html<?php //error_reporting(E_ALL) ; //echo "<br> From Textproc.php" ; $first = $_POST['first'] ; $second = $_POST['second'] ; //echo "<div id="myInnerDiv"> " ; echo "In testProc2, " . $first . " was first, and " . $second . " was second <br> " ; echo "Now another form from testproc2<br> " ; echo "<form name="form2"> " ; echo "First: <input type="text" name="uno"> <br> " ; echo "Second: <input type="text" name="dose"> <br> " ; echo " </form> " ; echo "<button type="button" onclick="changeInnerDiv">Change The Content</button> " ; ?> </body> </html>
上一篇: Spring Rest api和Spring基本安全
下一篇: 提交由ajax调用创建的ajax表单