gpt4 book ai didi

jquery - 如何通过c#在jquery json中加载arraylist

转载 作者:行者123 更新时间:2023-12-01 06:00:30 24 4
gpt4 key购买 nike

我正在尝试通过 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'>&nbsp;</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。它可能对你有帮助

Doing post back on an ajax toolkit modal popup extender

关于jquery - 如何通过c#在jquery json中加载arraylist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11912525/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com