【发布时间】:2013-08-01 13:51:45
【问题描述】:
我的 MVC 视图中有一个 HTML SPAN(类:displayText),它具有“typeId”和“idValue”属性。 目标是从传递的“typeId”和“idValue”的数据库表中获取 DisplayText 属性。
我的视图中有多个这样的 SPAN,所以我在 document.ready() 函数中调用以下方法来获取显示文本并将其显示在视图中,这样用户就不需要等待了。
$('span.displayText').each(
function (index) {
var url = $('#UrlGetDisplayName').val();
$.ajax({
type: "GET",
url: url,
data: ({ typeId: $(this).attr('typeId'),
value: $(this).attr('idValue')
}),
success: function (result) {
$('span.displayText')[index].innerText = result;
}
});
})
在上面的代码中,UrlGetDisplayName 是我的 MVC 视图上 HiddenField 的 ID,它包含以下 MVC 控制器操作的 URL,该操作负责从数据库中获取显示值。
[HttpGet]
public virtual JsonResult GetDisplayTextByType(string typeId, string idValue)
{
string displayText = "";
/* Code to call a database method to fetch text by type, and assign it to displayText */
return Json(displayText, JsonRequestBehavior.AllowGet);
}
这在 IE 和 Chrome 中完美运行,但在 Firefox 中它不会更新 SPAN 控件中的值。我可以在 Firebug 中监视正在调用的 Controller 操作,并且它返回正确的 Json 响应,但不更新跨度。可能的原因是什么?以及如何解决?
【问题讨论】:
-
.innerText 在 Firefox 中不起作用。 stackoverflow.com/questions/1359469/…
标签: asp.net-mvc json jquery