我正在使用AJAX表单将数据发送到另一个名为"show.php"的页面.这是页面的来源:
form.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="ajaxsbmt.js" type="text/javascript"></script>
</head>
<div id="MyResult"></div>
<form method="POST" action="response_norma.php" name="MyForm" onsubmit="xmlhttpPost('show.php', 'MyForm', 'MyResult', '<img src=\'indicator.gif\'>'); return false;">
<input type="text" name="mytext" size="20">
<input type="submit" value="Submit" name="ok">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
show.php
<?php
echo $_REQUEST['mytext'];
?>
Run Code Online (Sandbox Code Playgroud)
ajaxsbmt.js
function xmlhttpPost(strURL, formname, responsediv, responsemsg) {
var xmlHttpReq = false;
var self = this;
// xhr for Mozilla/Safari/Ie7
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// xhr for all other versions of IE
else if (window.ActiveXObject) { …Run Code Online (Sandbox Code Playgroud)