得到更新我有一個HTML SPAN(類:displayText),其中有「TYPEID」我的MVC視圖和「idValue」屬性。 目的是從傳遞「TYPEID」和「idValue」數據庫表獲取DisplayText屬性。JSON響應不能在Firefox
我在我的視圖中有這樣的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是HiddenField的對包含以下MVC的控制器動作,其負責從數據庫帶來顯示值的URL我的MVC圖的ID。
[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監視控制器動作被調用,也,它返回正確的JSON響應,但不更新跨度。可能的原因是什麼?以及如何解決它?
.innerText將無法工作在Firefox瀏覽器。 http://stackoverflow.com/questions/1359469/innertext-works-in-ie-but-not-in-firefox – anil