提交由ajax调用创建的ajax表单
三页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>
按下按钮可以按照预期调用页面testproc2.php,它确实回显表单中的两个值
<html> <head> </head> <body>但是当我按testproc2.php提交时没有任何反应。 我试过在testproc2.php中放入一个div,试着将java脚本移动到testproc2.php中。 提交什么都不做。 是否有可能有ajax调用返回可以提交的表单? 我宁愿不,但我需要jQuery吗? 感谢Brian 链接地址: http://www.djcxy.com/p/22329.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>