2

我想创建一个基于 ajax 的页面,我可以在其中调用另一个 php 文件中的表单以在用户请求时显示它,并通过另一个 ajax 提交表单数据。后面的过程很熟悉,但我对前者有些困惑。我该怎么做?谁能帮忙?

4

1 回答 1

0

You may be trying for this:

Consider this:

index.php(or other file where the form should be called):

<!doctype html>
<head>
<script>
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function(){
  if(xmlhttp.readyState==4&&xmlhttp.status==200){
    document.getElementById("result").innerHTML=xmlhttp.responseText;
  }
}
xmlhttp.open("GET", "form.php?id="+Math.random(), true);
xmlhttp.send();
function later_process(){//form submission here(since you are familiar.I may also provide it just give a comment.}
</script>
</head>
<body>
<div id="result"></div>
</body>
</html>

form.php

/* No body/head/!doctype declarations */
<form method="post">
</form>
于 2015-03-20T10:29:56.980 回答