https://stackoverflow.com/questions/49823763/handle-asmx-c-sharp-exception-with-fetch-api
https://stackoverflow.com/questions/51291831/fetch-api-call-causes-new-asp-net-session
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_api_fetch_easy
with ajax fetch api
https://stackoverflow.com/questions/60349890/jquery-async-await-ajax-call
https://stackoverflow.com/questions/27612372/how-to-await-the-ajax-request
<script>
getText("fetch_info.txt");
async function getText(file) {
let myObject = await fetch(file);
let myText = await myObject.text();
document.getElementById("demo").innerHTML = myText;
}
or
var params = { officeId: officeId, roleId: roleId };
var zoneId = 0;
$('#model').show();
async function fetchCall(data) {
url = '../DashboardReports/DashboardReports.aspx/LoadZoneList';
PostData = {
method: 'POST',
headers: {
"Accept": "application/json",
'Content-Type': 'application/json; charset=utf-8'
},
dataType: 'json'
};
if (data) { PostData.body = JSON.stringify(params) }
try {
const response = await fetch(url, PostData)
const jdata = await response.json();
if (!response.ok) {
alert(jdata.Message);
throw Error(jdata.Message)
}
else {
$("#ddlZone").empty();
$.each(jdata.d, function (key, value) {
$("#ddlZone").append($("<option></option>").val
(value.TableID).html(value.OffName));
if (zoneId == 0)
zoneId = value.TableID;
});
$("#ddlZone").multiselect('rebuild');
if (jdata.d.length > 0) {
$("#ddlZone").multiselect('selectAll', false);
$("#ddlZone").multiselect('updateButtonText');
}
//if (data.length == 1)
// $("#ddlZone").multiselect('selectAll', false);
//else {
// $("#ddlZone").multiselect('select', zoneId);
// $("#ddlZone").multiselect('updateButtonText');
//}
$("#hfZoneId").val('');
var zoneList = [];
$.each($("#ddlZone option:selected"), function () {
zoneList.push($(this).val());
});
$("#hfZoneId").val(zoneList);
LoadBranchList();
$('#model').hide();
}
} catch (e) {
$('#model').hide();
}
}
fetchCall(params);
No comments:
Post a Comment