Jquery ajax url在下拉列表更改时未被调用?
我试图在下拉菜单更改函数上调用jQueryAjax,但在更改下拉菜单时似乎什么也没发生。代码写在下面Jquery ajax url在下拉列表更改时未被调用?,jquery,asp.net,ajax,Jquery,Asp.net,Ajax,我试图在下拉菜单更改函数上调用jQueryAjax,但在更改下拉菜单时似乎什么也没发生。代码写在下面 $(document).ready(function () { $("#locationList").change(function () { FillCashSafe(); }) }); function FillCashSafe() { var locationNo = document.getE
$(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();
}
代码隐藏写在下面
$(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>
将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"));
}
});
是否调用了WebMethod?我的意思是是否调用了codebehind中的GetCashsafes方法?是的。如上所示,您是否收到任何错误消息或您的下拉列表中填写了Select One是的,我在error函数中添加了alertError,警报显示。我按照您的建议进行了尝试,但似乎什么也没有发生