按下浏览器后退按钮后,无法在页面加载时读取选定的下拉列表值。但这仅在第一次函数调用期间发生。我将详细解释:最初加载页面时,我附加了一个 ajax javascript,如下所示
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", "_Initialize_Chart();", true);
下面是javascript AJAX函数
function _Initialize_Chart() {
var selectedDeptId = $(ddlQueues).val();
var selectedMonth = $(ddlMonth).val();
var selectedYear = $(ddlYear).val();
$.ajax({
type: "GET",
url: ajaxCallHandlerUrl,
data: {
OpCode: "GetCallAverageMonthlyReportForGraph",
Params: "DeptId^" + selectedDeptId + "~Month^" + selectedMonth + "~Year^" + selectedYear
},
dataType: "xml",
beforeSend: function () {
$('#' + lblCallAverageDetails).html('');
document.getElementById(chartdiv).style.backgroundImage = "url('../images/ajax-loader_new_.gif')";
},
success: function (responseString) {
document.getElementById(chartdiv).style.backgroundImage = "";
_Load_Chart(responseString);
_Load_CallAverageGridData();
},
error: function (xhr, errorType, exception) {
var errorMessage = exception || xhr.statusText;
alert("There was an error Initializing Charts :: " + errorMessage);
}
});
}
function _Load_CallAverageGridData() {
var selectedDeptId = $(ddlQueues).val();
var selectedMonth = $(ddlMonth).val();
var selectedYear = $(ddlYear).val();
$.ajax({
type: "GET",
url: ajaxCallHandlerUrl,
data: {
OpCode: "GetCallAverageReportDetail",
Params: "DeptId^" + selectedDeptId + "~Month^" + selectedMonth + "~Year^" + selectedYear
},
dataType: "",
success: function (responseString) {
$('#' + lblCallAverageDetails).html(responseString);
},
error: function (xhr, errorType, exception) { //Triggered if an error communicating with server
var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText
alert("There was an error Fetching Call Average Data :: " + errorMessage);
}
});
}
所以这个 javascript 加载页面内容,它是一个图形和一个网格。单击网格中的行时,它会导航到另一个页面。现在按下浏览器后退按钮时,最初调用了上面显示的 javascript,但 var selectedMonth = $(ddlMonth).val();
没有给我下拉列表中实际选择的值的值。在第一次 Ajax 调用成功时,会进行另一个 Ajax 调用_Load_CallAverageGridData();
,在该调用中我得到了var selectedMonth = $(ddlMonth).val();
正确的值。任何人都可以阐明为什么会发生这种情况。