Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function () {
- $('#btn_user').click(function () {
- $.ajax({
- url: 'https://jsonplaceholder.typicode.com/users',
- method: 'GET',
- beforeSend: function (jqXHR, settings) {
- $('#btn_user').attr('disabled', 'disabled').find('i').addClass('fa-spin');
- $('#card-body').empty().append('<div class="col-md-12">\n' +
- '<h5 class="text-center"> <i class="fa fa-hourglass-half fa-spin"></i> Users loading .. . </h5>\n' +
- ' </div>')
- },
- success: function (users, textStatus, jqXHR) {
- $('#card-body').empty().append('<ul class="list-group" id="userList"></ul>');
- $('#btn_user').removeAttr('disabled').find('i').removeClass('fa-spin');
- $.each(users, function (i, user) {
- $('#userList').append('<li class="list-group-item" id="' + user.id + '">' + user.id + '. ' + user.name + '</li><button class="btn btn-danger"></button>')
- })
- }
- })
- })
- });
- $(function () {
- $('.btn').click(function () {
- alert('bosildi');
- var tempID = $(this).attr('id');
- $.ajax({
- url: 'https://jsonplaceholder.typicode.com/posts?userId=1',
- // url: 'https://jsonplaceholder.typicode.com/posts', data:{userID: tempID},
- // url: 'https://jsonplaceholder.typicode.com/posts?userID=' + tempID,
- method: 'GET',
- beforeSend: function (jqXHR, settings) {
- $('#infoField').empty().append('<div class="col-md-12">\n' +
- '<h5 class="text-center"> <i class="fa fa-spinner fa-spin"></i> Please wait .. . </h5>\n' +
- ' </div>')
- },
- success: function (posts, textStatus, jqXHR) {
- $('#infoField').empty();
- $.each(posts,function (i, post) {
- $('#infoField').append(' <div class="card-hea der bg-secondary"> User1'+tempID+'s Posts</div>\n' +
- '<div class="card-body">\n' +
- ' <strong>Title:'+post.title+'</strong>\n' +
- ' <strong>Body:'+post.body+'</strong>\n' +
- '</div>')
- })
- }
- });
- });
- });
- // function idnioldimi() {
- // var tempID = $(this).attr('id');
- // $('#infoField').append(tempID)
- // console.log(tempID);
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement