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
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



