一、发送请求
1.get请求
<button class="get">get请求</button>
<button class="ajget">ajax get请求</button>
<script src="js/jQuery1.12.4.js"></script>
<script>
$('.get').click(function(){
$.get('http://api.duyiedu.com/api/student/findAll',{appkey:'jimo_1590676767959'},function(data){
console.log(data);
},'json');
});
$('.ajget').click(function(){
$.ajax({
url:'http://api.duyiedu.com/api/student/findAll',
type:'get',
data:'appkey=jimo_1590676767959',
dataType:'json',
success:function(data){
console.log(data);
}
});
});
</script>
2.post请求
<input type="text" name="username" id="username">
<input type="password" name="password" id="password">
<button class="post">post</button>
<button class="ajpost">ajax post</button>
<script src="js/jQuery1.12.4.js"></script>
<script>
$('.post').click(function(){
var username = $('#username').val();
var password = $('#password').val();
$.post('http://api.duyiedu.com/api/student/stuLogin',{appkey:'jimo_1590676767959',account:username,password:password},function(data){
console.log(data);
},'json');
});
$('.ajpost').click(function () {
$.ajax({
url: 'http://api.duyiedu.com/api/student/stuLogin',
type: 'post',
data: {
appkey: 'kaivon_1574822824764',
account: $('#username').val(),
password: $('#password').val()
},
dataType: 'json',
success: function (data) {
console.log(data);
},
error: function (status) {
console.log('错误原因:' + status);
}
});
});
</script>
3.JSON请求
<button class="json">json请求</button>
<script src="js/jQuery1.12.4.js"></script>
<script>
$('.json').click(function(){
$.getJSON('http://api.duyiedu.com/api/student/findAll',{appkey:'jimo_1590676767959'},function(data){
console.log(data);
});
});
</script>