填充数据列表问题中的数据
Populating data in Datalist issue
我正在使用以下Javascript函数来填充Datalist
:
function GetDropDownData(f) {
$.ajax({
url: '/Rentals/Base/GetContactsForFacility?selectedFacility=' + f,
data: { facility: f },
dataType: 'json',
success: function (result) {
response($.map(result, function (item) {
$('#custServiceContactsSelection').append($("<option />").val(item.ContactName).text(item.ContactName));
}));
},
cache: false,
error: function (jqXHR, textStatus, errorThrown) {
if (errorThrown.indexOf("Your session has timed out") != -1) {
location.href = "/Rentals/Base/Timeout";
}
}
});
}
以下是我的控制器内部的方法:
public ActionResult GetContactsForFacility (string selectedFacility)
{
var facilityId = new Guid(selectedFacility);
if (Request.IsAjaxRequest())
{
var contacts = SessionService.AllCustomerServiceContactsForFacility(CrmService, facilityId);
return Json(contacts.Select(x => new { label = x.ContactName }), JsonRequestBehavior.AllowGet);
}
return Content(string.Empty);
}
当我尝试运行这个时,它会从Controller返回。但是,在那之后,我在VS中出错:JavaScript runtime error: 'response' is undefined
我认为,函数GetDropDownData()
中缺少了一些东西,但无法弄清楚到底是什么
请你给我带路好吗?谢谢
在AJAX请求中,您需要将其更改为:
success: function ( response ) {
$.map(response, function (item) {
$('#custServiceContactsSelection').append($("<option />").val(item.ContactName).text(item.ContactName));
});
},
// rest of code
相关文章:
- 要求输入在数据列表中
- 使用JavaScript在IE9中获取数据列表选项
- 使用AJAX创建数据列表
- 从要使用Protractor测试的服务器异步加载的动态数据列表的列表
- 为什么数据列表选项的id返回空值
- 如何调用更改事件,例如在 HTML 数据列表上选择
- 在 d3 中为数据列表创建元素
- asp.net 数据列表中的跟踪标签 ID
- 通过遍历JSON文件来填充数据列表选项
- PHP:从数据列表中打印(循环困难)
- 无法获取数据列表中项目的值
- 从不同页面收集数据以形成数据列表,并将它们一起发送
- 检查给定的数据列表中是否存在表单字段值
- Jquery调用数据列表选项卡或输入
- 按调用顺序返回由Ajax/HTTP生成的数据列表
- 如何根据输入值可靠地计算数据列表中的匹配数
- 如何在angularJs中使用数据列表
- 如何检测从数据列表中选择时更改的输入字段
- 将文件转换为数组并使用数据列表和选项标签为自动完成文本框添加数组元素
- Zend Form 1.x使用html5数据列表标签