22、HTML表单增强:从原生到插件的实现

HTML表单增强:从原生到插件的实现

1. Ajax表单提交

在网页交互中,使用Ajax提交表单可以避免页面的整体刷新,提升用户体验。以下是一段实现Ajax表单提交的代码:

// ...
// this tells the server-side process that Ajax was used
$('input[name="usingAJAX"]',this).val( 'true' );
// store reference to the form
var $this = $(this);
// grab the url from the form element
var url = $this.attr('action');
// prepare the form data to send
var dataToSend = $this.serialize();
// the callback function that tells us what the server-side process had to say
var callback = function(dataReceived){
    // hide the form (thankfully we stored a reference to it)
    $this.hide();
    // in our case the server returned an HTML snippet so just append it to 
    // the DOM
    // expecting: <div id="result">Your 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值