【发布时间】:2012-07-25 23:00:04
【问题描述】:
为什么设置数据在$getJson 调用中不起作用。 getJson 调用中未设置 WTF 变量。另外,另一个问题是为什么不能在getJson 调用中设置$(this).html()。我在全局范围内定义了 wtf 变量,但我没有从 getJson 函数中获取值,我想知道为什么无法访问数据。这由ajax 函数和async: seto to false 解决。我有我的解释,但我想要你的解释,所以提前谢谢。
<script type="text/javascript">
$(function () { $('a[id=talentNaslov]').before(function () {
var id = $(this).html();
var data=null;
$.getJSON("url", { id: id },function (talentNaziv) {
data=talentNaziv;
// data variable is not set still null and also $(this) is not set when i use it//
});
$(this).html(data);
});
});
</script>
【问题讨论】:
-
您认为“之前”会如何运作?数据的问题在于它是异步设置的,但您正在同步访问它。
-
你的意思是同步调用的顺序是什么?
-
我已经添加了一些解释
-
请查看更新后的答案
标签: ajax asp.net-mvc-3 jquery asp.net-ajax