Last active
October 7, 2018 15:32
-
-
Save qqpann/42ac06b1064c999d1edf2c63ad33ed50 to your computer and use it in GitHub Desktop.
[Ajax Quickstart] Ajax quickstart template #ajax
This file contains hidden or 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
<!-- thanks: https://qiita.com/zakiyamaaaaa/items/bdda422db2ccbaea60d9 --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<button id="ajax">ajax</button> | |
<div class="result"></div> | |
<script type="text/javascript"> | |
$(function(){ | |
// Ajax button click | |
$('#ajax').on('click',function(){ | |
$.ajax({ | |
url: "{% url 'ajax_article_list' %}", | |
type:'GET', | |
data:{ | |
'userid':$('#userid').val(), | |
'passward':$('#passward').val(), | |
} | |
}) | |
// Ajaxリクエストが成功した時発動 | |
.done( (data) => { | |
$('.result').html(data); | |
console.log(data); | |
}) | |
// Ajaxリクエストが失敗した時発動 | |
.fail( (data) => { | |
$('.result').html(data); | |
console.log(data); | |
}) | |
// Ajaxリクエストが成功・失敗どちらでも発動 | |
.always( (data) => { | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment