jQuery Form Plugin:ajaxForm 简易使用方法

<!--1.先引入 jQuery,再引入 ajaxForm -->
<script type="text/javascript" src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.form.js"></script>
<script type="text/javascript">

// 2.把表单 bind 到 ajaxForm
$("#formCreditCard").ajaxForm({
beforeSubmit: showRequest,
dataType: "text",
success: showResponse
});

// 3.写对应的 function:表单送出前的处理 ajaxForm pre-submit callback
function showRequest(formData, jqForm, options) {
var queryString = $.param(formData);
alert(queryString);
return true;
}

// 4.写对应的 function:表单送出后 Server 端回传的处理 ajaxForm post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
alert(responseText); //单纯的Text
}

</script>

<!--5.送出表单-->
<form id="formCreditCard" method="post" accept-charset="UTF-8" >
<input type="submit" name="btnSubmit" value="送出">
<input type="text" name="MerchantID" value="1000070" /><br />
<input type="text" name="MerchantTradeDate" value="20199/09/23 15:39:30" /><br />
</form>

※ 下列语法可 unbind ajaxForm


<span class="token operator">&lt;</span>script type<span class="token operator">=</span><span class="token string">"text/javascript"</span><span class="token operator">&gt;</span>
 <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'#formCreditCard'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">ajaxFormUnbind</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token operator">&lt;</span><span class="token operator">/</span>script<span class="token operator">&gt;</span>

参与评论