gpt4 book ai didi

javascript - 使用 AJAX 更新 DropDownList

转载 作者:行者123 更新时间:2023-12-02 23:30:33 25 4
gpt4 key购买 nike

输入客户端名称#NAME1后,我尝试从数据库中的其他表获取列表中的此客户端子帐户#SUB,但我的列表为空。我做错了什么?

html

 <script type="text/javascript">
var kunnr; var ROLA;
$(document).ready(function () {

$('#NAME1').autocomplete({
source: function (request, response) {
$.ajax({
url: "Form2",
method: 'POST',
data: {
term: $('#NAME1').val()
},
success: function (data) {
response(data);
}});},
select: function (event, ui) {
kunnr = ui.item.kunnr;
}});});
$('#NAME1').change; ({
source: function (request, response) {
$.ajax({
type: "GET",
url: "Form3",
method: 'POST',
data: {
term: $('#SUB').val(), kunnr: kunnr, ROLA:"Slave"
},
success: function (data) {
response(data);
}});}, });

Controller

    [HttpPost]
public JsonResult Form2(string term)
{
return Json(db.KLIENCI.Where(c => (term!=null && c.NAME1.Contains(term))||(term==null)).OrderBy(x=>x.NAME1).Take(10).Select(a => new { label = a.NAME1,kunnr=a.KUNNR }));
}
[HttpPost]
public JsonResult Form3(string term, string kunnr)
{
return Json(db.CLI2LOGIN.Where(c => ((term != null && c.LOGIN.Contains(term)) || (term == null))&& c.KUNNR== kunnr && c.ROLA == "Slave").OrderBy(x => x.LOGIN).Select(a => new { label = a.LOGIN }).ToList(),JsonRequestBehavior.AllowGet);}

最佳答案

请在下面找到一个示例:

查看:

<script>
$(document).ready(function () {
$('.maincat').change(function () {
updateSubCategoryList($(this).val());
});

function updateSubCategoryList(catId) {
$('.subcat').empty();
$('.subsubcat').empty();
$.ajax({
url: '@Url.Action("GetSubCategories")',
type: 'Get',
data: { main: catId },
success: function (response) {
var subcat = $('.subcat');
subcat.append('<option value=""></option>');
if (response != null && response != '') {
$.each(response, function (index, value) {
subcat.append('<option value="' + this.SubCategoryID + '">' + this.SubCategoryDescription + '</option>');
});
}
}
});
}
</script>

Controller :

        [HttpGet]
public JsonResult GetSubCategories(int main)
{
var i = _jobsservice.GetSubCategories(main);
return Json(i, JsonRequestBehavior.AllowGet);
}

关于javascript - 使用 AJAX 更新 DropDownList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56524139/

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