$.get(URL,data,function(data,status,xhr),dataType)
Tham khảo: https://www.w3schools.com/jquery/ajax_get.asp
- Ví dụ lấy nội dung
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
JSON.stringify(data ) để xem chi tiết đối tượng
- Ví dụ lấy nội dung tử JSon
$("#Button1").click(function(){
$.get("Build_Json.aspx", function(data, status){
$.each(data, function (index, itemData) {
alert( itemData.TenTruongJSon);
});
});
});
*** Áp dụng cho iif khi lập trình phần mềm
Căn cứ vào ID Query trả về, ví dụ ID là Q1
idDH=urlGetValuePara("idDH");
$.get("/adminxml/Query_Do.aspx?name=TEN&out=json&id="+idDH, function(data, status){
alert( JSON.stringify(data ) ); để xem chi tiết đối tượng
alert( data.Q1.length); // Lấy tổng sổ bảng ghi
alert( data.Q1[0].TenCot); // Lấy giá trị cột ta ở dòng 1 , TenCot đổi lại cho phù hợp
$.each(data.Q1, function (index, itemData) {
alert( itemData.TenTruongJSon);
}); //each
}); //get
- Ví dụ nạp dữ liệu vào Select
$.get("/adminxml/Query_Do.aspx?name=KeToanBanHang/DMTK_Loc&out=json&loai=1,2", function(data, status){
// alert(JSON.stringify(data ) );
$.each( data.Q1, function (index, itemData) {
// alert( itemData.MaTaiKhoan);
$('#TKCo').append($('<option></option>').val(itemData.MaTaiKhoan).html(itemData.MaTaiKhoan)
);
}); //each
}); //get
- Ví dụ thực thi Javascript
$.ajax({
method: "GET",
url: "test.js",
dataType: "script"
});
- Ví dụ : khi nhập từ input lấy dữ liệu từ server
<script>
$(document).ready(function(){
$("input").keyup(function(){
var txt = $("input").val();
$.post("demo_ajax_gethint.asp", {suggest: txt}, function(result){
$("span").html(result);
});
});
});
</script>
- Ví dụ: sử dụng $http lấy dữ liệu - áp dụng trong Angular
var url= "url_get";
//alert(url);
//$http
$http({
method : "GET",
url : url
}).then(function mySuccess(response)
{
//response.data.Table;
}//then
,function myError(response)
{
alert( "LỖI:"+ response.statusText );
}
); //$http
Ajax Jquery GET