Created
August 25, 2017 03:59
-
-
Save soiqualang/840ed2ed9b3417be876473e8e61e7aea to your computer and use it in GitHub Desktop.
Hàm gọi Ajax phía client
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
$(document).ready(function(){ | |
// Gắn sự kiện onclick vào #viewbtn | |
$('#viewbtn').click(function() { | |
$('#loading').html('Loading...'); | |
var strURL = $('#base_url').val(); | |
$.ajax({ | |
url: strURL, | |
type: 'POST', | |
cache: false, | |
data: 'getMember=view', | |
success: function(string){ | |
/** | |
* Kiểu mặc định trả về là dạng String, bạn dùng hàm parseJSON để phân tích dữ liệu trả về | |
* có 2 cách parse JSON là : JSON.parse() và $.parseJSON(); | |
* 1. var getData = JSON.parse(string); | |
* 2. var getData = $.parseJSON(string); | |
**/ | |
var getData = $.parseJSON(string); | |
//input dữ liệu lấy về từ server vào textbox | |
$('#txt_username').val(getData.username); | |
$('#txt_password').val(getData.password); | |
$('#txt_email').val(getData.email); | |
//Trả loading về trạng thái ban đầu | |
$('#loading').html(' '); | |
}, | |
error: function (){ | |
alert('Có lỗi xảy ra'); | |
} | |
}); | |
}); | |
// Gắn sự kiện onclick vào #resetbtn | |
$('#resetbtn').click(function() { | |
$('input:text').val(''); // xóa hết dữ liệu trong textbox | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment