Skip to content

Instantly share code, notes, and snippets.

@soiqualang
Created August 25, 2017 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soiqualang/840ed2ed9b3417be876473e8e61e7aea to your computer and use it in GitHub Desktop.
Save soiqualang/840ed2ed9b3417be876473e8e61e7aea to your computer and use it in GitHub Desktop.
Hàm gọi Ajax phía client
$(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