你有两个选择——
选项 1:通过 Javascript 提交表单
<form action="http://www.yoursite.com/form.xxx" method="post">
<input type="button" name="editgroupscript" class="btn green" value="Submit" onclick="formSubmitFunction()" />
</form>
Javascript:
function ajax() {
var obj;
if(window.ActiveXObject) {
try {
obj = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else {
obj = new XMLHttpRequest();
}
return (obj);
}
function formSubmitFunction() {
// Creating the POST body
var myForm = document.forms["myForm"];
var value1 = myForm["value1"].value;
var value2 = myForm["value2"].value;
var parameters = "value1="+value1+"&value2="+value2;
// Sending a POST via AJAX
var ajax = ajax();
ajax.onreadystatechange = function () {
if((ajax.readyState == 4) && (ajax.status == 200)) {
// Action on successful response
}
};
ajax.send("POST", "yourURL", true);
ajax.send(parameters);
}
选项 2:将表单定位到 iframe
<form action="http://www.yoursite.com/form.xxx" method="post" target="iframe">
<input type="submit" name="editgroupscript" class="btn green" value="Submit"/>
</form>
<iframe src="about:blank" style="display:none" id="iframe" name="iframe"></iframe>
Javascript:
var iframe = document.getElementById("iframe");
iframe.onload = function () { formSubmitResponse(iframe); };
function formSubmitResponse(iframe) {
var idocument = (iframe.contentDocument || iframe.contentWindow.document);
if(idocument) {
var responseFromBackend = idocument.getElementsByTagName("body")[0].innerHTML;
}
}
以下是使用 iframe 时发生的情况: 1. 单击提交按钮。2. 表单参数被提交到后端脚本。3. 页面不刷新。4. 后端脚本的输出被发送到 iframe。5.这个方法模仿AJAX!