Jquery easyui異步提交表單的兩種方式示例詳解
這篇文章分享一下easyui常用的兩種表單異步提交的方式。
開始前的準(zhǔn)備工作
1、使用HBuilderX創(chuàng)建一個(gè)簡(jiǎn)單的html項(xiàng)目,刪除img和html目錄,只保留js目錄和index.html;
2、下載jquery.min.js和jquery.easyui.min.js,復(fù)制到j(luò)s目錄下;
3、修改index.html的代碼,增加一個(gè)表單,包含三個(gè)輸入框和一個(gè)提交按鈕,在頁面引入easyui的js文件;

頁面效果如下:

方式一:利用jquery ajax提交
這種方式只需要引入jquery.min.js
$.post()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>easyui異步提交表單</title>
<script src="js/jquery.min.js"></script>
</head>
<body>
<form id="ajax_form">
姓名:<input id="name" />
年齡:<input id="age" />
手機(jī)號(hào):<input id="phone" />
<button type="button" id="submit">提交</button>
</form>
<script>
$(function(
$("#submit").click(function() {
$.post("/xxx/save", {
name: $("#name").val(),
age: $("#age").val(),
phone: $("#phone").val()
}, function(resp) {
// 處理響應(yīng)的數(shù)據(jù)
}, "json");
});
));
</script>
</body>
</html>$.ajax()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>easyui異步提交表單</title>
<script src="js/jquery.min.js"></script>
</head>
<body>
<form id="ajax_form">
姓名:<input id="name" />
年齡:<input id="age" />
手機(jī)號(hào):<input id="phone" />
<button type="button" id="submit">提交</button>
</form>
<script>
$(function(
$("#submit").on("click", function() {
$.ajax({
url: "/xxx/save",
type: "post",
data: {
name: $("#name").val(),
age: $("#age").val(),
phone: $("#phone").val()
},
async: true,
cache: false,
dataType: "json",
processData: true,
success: function(resp) {
// 處理成功的響應(yīng)
},
error: function(resp) {
// 處理失敗的響應(yīng)
}
});
});
));
</script>
</body>
</html>方式二:使用easyui提供的表單提交方式
easyui官網(wǎng)已經(jīng)介紹了這種方式,不過和上面的ajax提交不一樣,這種提交方式要給輸入框設(shè)置name屬性。

案例代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>easyui異步提交表單</title>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.easyui.min.js"></script>
</head>
<body>
<form id="ajax_form" method="post">
姓名:<input name="name" />
年齡:<input name="age" />
手機(jī)號(hào):<input name="phone" />
<button type="submit">提交</button>
</form>
<script>
let requestUrl = "/xxx/save";
$(document).ready(function() {
$("#ajax_form").form({
url: requestUrl,
success: function(resp) {
// 處理成功的響應(yīng)
}
});
});
</script>
</body>
</html>到此這篇關(guān)于Jquery easyui異步提交表單的兩種方式的文章就介紹到這了,更多相關(guān)jquery easyui異步提交表單內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
jquery實(shí)現(xiàn)metro效果示例代碼
metro效果想必大家并不陌生吧,下面為大家講解下在jquery中時(shí)如何實(shí)現(xiàn)的,新手朋友們可不要錯(cuò)過了2013-09-09
jQuery+Datatables實(shí)現(xiàn)表格批量刪除功能【推薦】
這篇文章主要介紹了jQuery+Datatables實(shí)現(xiàn)表格批量刪除功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10
jquery中val()方法是從最后一個(gè)選項(xiàng)往前讀取的
這篇文章主要介紹了jquery中val()方法是從最后一個(gè)選項(xiàng)往前讀取的,需要的朋友可以參考下2015-09-09
jquery中的 $("#jb51")與document.getElementById("
以前沒注意過,認(rèn)為jquery 中的 $("#jb51") 與 document.getElementById("jb51") 是一回事,指的是同一個(gè)東西。2011-07-07
jQuery plugin animsition使用小結(jié)
本文通過實(shí)例代碼給大家分享了jQuery plugin animsition用法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧2017-09-09
Jquery獲取復(fù)選框被選中值的簡(jiǎn)單方法
這篇文章介紹了Jquery獲取復(fù)選框被選中值的簡(jiǎn)單方法,有需要的朋友可以參考一下2013-07-07

