日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【jQuery】使用jquery.form.js,获取提交表单返回值

發(fā)布時間:2024/2/28 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【jQuery】使用jquery.form.js,获取提交表单返回值 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

jQuery表單庫介紹

實(shí)現(xiàn) html 中提交表單并實(shí)現(xiàn)不跳轉(zhuǎn)頁面處理返回值

jQuery表單庫(jquery.form.js庫)以jQuery為基礎(chǔ),用于處理表單AJAX提交,使得表單AJAX提交簡單、容易,且能完整控制提交過程和處理結(jié)果,不需要任何特殊標(biāo)簽輔助,不影響原表單結(jié)構(gòu),只要使用該庫就能使普通表單平滑升級為ajax提交表單。

官方地址:https://github.com/jquery-form/form

源代碼查看和下載地址:https://github.com/jquery-form/form/blob/master/src/jquery.form.js

AjaxForm使用示例

1、導(dǎo)入js文件

需要導(dǎo)入相關(guān)的js文件。使用ajaxForm方式需要使用到j(luò)query和jquery-form兩個js文件。如:

<script type="text/javascript" src="/static/js/jquery-1.7.2.js"></script><script type="text/javascript" src="/static/js/jquery.form.min.js"></script>

2、綁定表單

表單綁定它一般在$(document).ready(function () {}里定義,它能讓表單不刷新頁面的情況下POST到目標(biāo)。如:

表單示例

<form id="editor_form" action="/api/editor/update" method="post"><input type="hidden" name="id" value="3"/><input type="submit" value="提交"> </form>

JS示例

// wait for the DOM to be loaded$(document).ready(function () {// bind 'myForm' and provide a simple callback function$('#editor_form').ajaxForm(function (message) {var messageJson = JSON.parse(message);if (messageJson.status == '0') {alert("保存成功!");} else {alert("保存失敗,請聯(lián)系管理員!" + message);}});});

3、運(yùn)行效果

附:官方文檔

Overview

The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX. The main methods, ajaxForm and ajaxSubmit, gather information from the form element to determine how to manage the submit process. Both of these methods support numerous options which allows you to have full control over how the data is submitted. Submitting a form with AJAX doesn’t get any easier than this!

1 Add a form to your page. Just a normal form, no special markup required:
<form id="myForm" action="comment.php" method="post">Name: <input type="text" name="name" />Comment: <textarea name="comment"></textarea><input type="submit" value="Submit Comment" /> </form>
2 Include jQuery and the Form Plugin external script files and a short script to initialize the form when the DOM is ready:
<html> <head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script><script src="http://malsup.github.com/jquery.form.js"></script><script>// wait for the DOM to be loaded$(document).ready(function() {// bind 'myForm' and provide a simple callback function$('#myForm').ajaxForm(function() {alert("Thank you for your comment!");});});</script> </head> ...

That’s it!

When this form is submitted the name and comment fields will be posted to comment.php. If the server returns a success status then the user will see a “Thank you” message.

總結(jié)

以上是生活随笔為你收集整理的【jQuery】使用jquery.form.js,获取提交表单返回值的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。