我是AJAX和jQuery的新手,我不知道如何使用jQuery在modal中使用ajax加载数据。
我只是在使用
(document).ready(function () {(
)};
通过使用此功能,document.ready
功能中的代码将以非绑定方式放置。
我正在寻找使用AJAX使Modal更准确的最佳方法。
代码:
<script>
$(document).ready(function () {
//*** function to getmaxcode of voucher type from database
function getMaxCodeForVoucherType(urlStr, VrType) {
if (VrType !== "") {
$.ajax({
url: urlStr,
type: "GET",
data: { VoucherTypeId: VrType },
dataType: 'json',
success: function (response) {
//***Generate Options Via Ajax Response
var elemVoucherTypeTypeCode = $('#voucherCode');
elemVoucherTypeTypeCode.val('');
if (response.Success === true) {
var maxCode = response.Data.voucherMaxCode;
elemVoucherTypeTypeCode.val(maxCode);
}
//alert(output);
},
error: function (response) {
console.log("No record Found");
},
});
}
}
//**Fetching the record for cash accounts from database
var DOCUMENT = $("#modal_backdropCashVoucher");
$(DOCUMENT).load(function () {
var debitAccounts = $("#DACC");
var url = "@Url.Action("GetAllDetailedCashAccounts", "Vouchers")";
var urlStr1 = "@(Url.Action("GetMaxCodeByVoucherTypeId", "Vouchers"))";
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
data:{},
success: function (response) {
debitAccounts.html('<option value=""></option>');
if (response.Success === true) {
for (i in response.DataSet) {
if (response.DataSet.hasOwnProperty(i)) {
debitAccounts.append('<option value="' + response.DataSet[i].Id + '">' + response.DataSet[i].Name + '</option>');
}
}
}
},
cache: false
});
getMaxCodeForVoucherType(urlStr1, 2);
// }); // end voucher types changing mode
//*** START -------- Credit Account behavour
var allCashAccounts = $("#creditAccount");
var url = "@Url.Action("GetAllDetailedAccounts", "Vouchers")";
$.ajax({
type: 'GET',
url: url,
dataType: 'json',
data:{},
success: function (response) {
allCashAccounts.html('<option value=""></option>');
if (response.Success === true) {
for (i in response.DataSet) {
if (response.DataSet.hasOwnProperty(i)) {
allCashAccounts.append('<option value="' + response.DataSet[i].Id + '">' + response.DataSet[i].Name + '</option>');
}
}
}
},
cache: false
});
//*** END -------- Credit Account behavour
//========================================================================
//=====END=======Dynamic behaviour of voucehr on voucher type ==========
//========================================================================
});
});//eFuntionnding main
</script>
我想以更好的方式做这件事,请给我一条向正确方向前进的道路。