我正在尝试处理提交表单的完整事件。我准备这样的表格:
var _url="../ex/tem?sessionId="+sessId;
var form = document.createElement("form");
form.setAttribute("id", "myForm");
form.setAttribute("method", "post");
form.setAttribute("action", _url);
form.setAttribute("enctype", "multipart/form-data");
form._submit_function_ = form.submit;
var textName=document.createElement("input");
textName.setAttribute("type", "hidden");
textName.setAttribute("name", "textName");
textName.setAttribute("value", textName);
form.appendChild(textName);
document.body.appendChild(form);
我这样提交:
form._submit_function_();
我如何抓住完整的活动?
答案 0 :(得分:1)
可能重复How do I capture response of form.submit
一般来说,"提交"将数据发布到另一个页面,因此它更像是一个重定向..没有"之后"这样的事件,不是我所知道的..
您通常使用像ajax这样的内容将数据发布到另一个页面,等待响应数据,然后继续前进。
使用表单,像jquery这样的东西会简单地抓取所有控件并将它们保存为值数组并在提供响应和错误回调/事件时发布它们。
编辑: 与jquery的方式一样......(来自Duplicate Page的示例)
$('#myFormElement').ajaxForm({
url : 'Page_That_Will_Send_A_Response.php', // or whatever
dataType : 'json',
success : function (response) {
// The object of response is a PHP array or object normally.. easy to build
alert("The server says: " + response);
}
})
jQuery AJAX信息:http://api.jquery.com/jquery.ajax/