Created
August 23, 2016 10:07
-
-
Save ckentq/5ce2b768b99d7b3b034200b3dd04c4bc to your computer and use it in GitHub Desktop.
ajax sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var url = $('#main-wrapper').attr('data-url'); | |
var loading = $('.loading'); | |
$('.submit').on('click', function(){ | |
var formData = $('.createForm').serialize(); | |
loading.removeClass('hide');//顯示儲存中 | |
$.post(url, formData,function(){},'json') | |
.done(function(callback){ | |
if(callback.success){ | |
//成功之後要做的事情 | |
}else{ | |
// 失敗之後要做的事情 | |
} | |
loading.addClass('hide'); | |
}).fail(function(callback){ | |
//連現階段錯誤失敗訊息 | |
loading.addClass('hide'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div data-url="domain/news/update" id="main-wrapper"> | |
<form class="createForm"> | |
<input name="xxx"> | |
<button class="submit">送出</button> | |
</form> | |
</div> | |
<div class="loading hide">我是處理中的特效</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment