使用 jquery 绑定下拉列表
我尝试使用 jquery 绑定 dropdowmlist。但显示一些错误。
代码:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{product: '" + product + "'}",
url: "Search.aspx/FetchCategory",
dataType: "json",
success: function(data) {
$.each(data.d, function() {
$("#ddlCategory").append($("<option></option>").val(this['ID']).html(this['Category']));
});
}
});
数据中的值: [{"类别":"全部","ID":"%"},"类别":"动作,"ID":"4"},"类别":"种族,"ID":"5"} ,"类别":"体育,"ID":"6"}]
错误:
$("#ddlCategory").append($("").val(this['ID']).html(this['类别'])); Microsoft JScript 运行时错误:对象不支持此属性或方法
Geetha
I am try to bind the dropdowmlist using jquery. But is showing some error.
Code:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{product: '" + product + "'}",
url: "Search.aspx/FetchCategory",
dataType: "json",
success: function(data) {
$.each(data.d, function() {
$("#ddlCategory").append($("<option></option>").val(this['ID']).html(this['Category']));
});
}
});
values in the data:
[{"Category":"All","ID":"%"},"Category":"Action,"ID":"4"},"Category":"Race,"ID":"5"},"Category":"Sports,"ID":"6"}]
Error:
$("#ddlCategory").append($("").val(this['ID']).html(this['Category']));
Microsoft JScript runtime error: Object doesn't support this property or method
Geetha
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
吉萨:
看起来 data.d 返回一个包含对象的数组?
尝试像这样实现成功:
Geetha:
It looks like data.d is returning an array which contains objects?
Try implementing success like this: