我正在尝试在下拉列表更改功能上调用jquery ajax。但是在更改下拉列表时似乎没有任何事情发生。代码写在下面
$(document).ready(function () {
$("#locationList").change(function () {
FillCashSafe();
})
});
function FillCashSafe() {
var locationNo = document.getElementById('<%=locationList.ClientID%>').value;
alert(locationNo);//**alert is working properly**
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '<%=ResolveUrl("~/HealthReport.aspx/GetCashsafes") %>',
data: "{}",
dataType: "json",
success: function (data) {
$.each(data.d, function (key, value) {
$("#CashSafeList").append($("<option></option>").val(value.CashsafeId).html(value.CashsafeDisplaySerialNo));
});
},
error: function (result) {
$("#CashSafeList").append($("<option></option>").val("-1").html("Select one"));
}
});
}
背后的代码写在下面
[WebMethod]
public static Cashsafe[] GetCashsafes(string Location)
{
Decimal userId = (Decimal)AMSECSessionData.userId;
List<Cashsafe> cashsafes = DropDown.getCashSafeListLocationwise(userId, Convert.ToInt32(Location));
return cashsafes.ToArray();
}
标记如下
<div class="controls">
<select class="chzn-select" data-rel="chosen" id="locationList" name="Location" runat="server">
</select>
</div>
答案 0 :(得分:0)
将httppost属性放在服务器方法上,然后重试
[WebMethod]
[HttpPost]
public static Cashsafe[] GetCashsafes(string Location)
{
Decimal userId = (Decimal)AMSECSessionData.userId;
List<Cashsafe> cashsafes = DropDown.getCashSafeListLocationwise(userId, Convert.ToInt32(Location));
return cashsafes.ToArray();
}
和aloso传递位置如下所示
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: '<%=ResolveUrl("~/HealthReport.aspx/GetCashsafes") %>',
data: "{'Location' : locationNo}",
dataType: "json",
success: function (data) {
$.each(data.d, function (key, value) {
$("#CashSafeList").append($("<option></option>").val(value.CashsafeId).html(value.CashsafeDisplaySerialNo));
});
},
error: function (result) {
$("#CashSafeList").append($("<option></option>").val("-1").html("Select one"));
}
});