作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过 jquery/json ajax 方法为 jquery 自动完成组合框加载数据表中的数据,但它不起作用,这是我的代码:
我的脚本:
<script type='text/javascript'>//<![CDATA[
$(function() {
// filter
$.widget("ui.combobox", {
_create: function() {
var self = this,
select = this.element.hide(),
selected = select.children(":selected"),
value = selected.val() ? selected.text() : "";
var input = this.input = $("<input>").insertAfter(select).val(value).autocomplete({
delay: 0,
minLength: 0,
source: function(request, response) {
$.ajax({
url: "InventoryDetails_new.aspx/BindHostDetails('SIU')",
type: "POST",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function(data) {
response($.map(data.geonames, function(item) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.name
}
}));
}
})
},
select: function(event, ui) {
},
}).addClass("ui-widget ui-widget-content ui-corner-left");
input.data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.label + "</a>").appendTo(ul);
};
this.button = $("<button type='button'> </button>").attr("tabIndex", -1).attr("title", "Show All Items").insertAfter(input).button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
}).removeClass("ui-corner-all").addClass("ui-corner-right ui-button-icon").click(function() {
// close if already visible
if (input.autocomplete("widget").is(":visible")) {
input.autocomplete("close");
return;
}
// work around a bug (likely same cause as #5265)
$(this).blur();
// pass empty string as value to search for, displaying all results
input.autocomplete("search", "");
input.focus();
});
},
destroy: function() {
this.input.remove();
this.button.remove();
this.element.show();
$.Widget.prototype.destroy.call(this);
}
});
$("#cbCity").combobox({
source: "InventoryDetails_new.aspx/BindHostDetails('SIU')",
dataType: "jsonp",
minLength: 2,
select: function(event, ui) {
log(ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.id : "Nothing selected, input was " + this.value);
}
});
}); //]]>
</script>
[WebMethod]
public ArrayList BindHostDetails(string strStockCategory)
{
string strSql = "";
if (strStockCategory == "SIU")
{
strSql = "select distinct(nvrHostName) from tblInventoryDetails where intStatus =1 and nvrStockCategory = '" + strStockCategory.ToString() + "'";
}
else
{
strSql = "select distinct(nvrHostName) from tblInventoryDetails where intStatus = 0 and nvrStockCategory = '" + strStockCategory.ToString() + "'";
}
DataTable objDT = new DataTable();
objDT = objDataLayer.GetDataStoreInTable(strSql);
DataSet ds = new DataSet();
ds.Tables.Add(objDT);
ArrayList arrlst = new ArrayList();
foreach (DataRow row in ds.Tables[0].Rows)
{
arrlst.Add(row);
}
return arrlst;
}
最佳答案
您使用了错误的方式调用 webmethod。它可能对你有帮助
关于jquery - 如何通过c#在jquery json中加载arraylist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11912525/
我是一名优秀的程序员,十分优秀!