juqery ajax获取的数据 第一次不显示 第二次才能显示

牛魔王 2012-04-28 03:25:26
<ul id="Menu">
<li title="1"><a>管理片区</a></li>
</ul>



juqery:

$(function(){
$("#Menu li").hover(
function(){
id=$(this).attr("title")
li=$(this)
ul=$(this).children("ul");
$.get("OrganizeCity-model-get.php",{id:id},function(data){li.append(data);})

$(this).children("a").stop(true,true).animate({"backgroundColor":"#111"}).end().siblings("a").animate({"backgroundColor":"#333"});
$(this).children("ul").stop(true,true).fadeIn(300);

},
function(){
$(this).children("ul").stop(true,true).fadeOut(300);
$(this).children("a").stop(true,true).animate({"backgroundColor":"#333"});
})


})



为什么第一次hover不显示返回的data ,要再次触发事件才能显示呢?如何改进?
...全文
377 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
牛魔王 2012-05-02
  • 打赏
  • 举报
回复
$.get("OrganizeCity-model-get.php",{id:id},function(data){li.append(data).children("ul").show();})

这样就好使了,很无解,为什么一定要这样写呢,在一个funciton(){}中写的代码还不是一次执行吗?
qq120848369 2012-04-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

如果代码逻辑没有问题。那么可以在

$.get("OrganizeCity-model-get.php",{id:id},function(data){li.append(data);})
alert("sf");
$(this).children("a").stop(true,true).animate({"backgroundColor":"#111"}).end().sibli……
[/Quote]

求推荐学习jquery的好办法好书籍。。
coder 2012-04-28
  • 打赏
  • 举报
回复
如果代码逻辑没有问题。那么可以在

$.get("OrganizeCity-model-get.php",{id:id},function(data){li.append(data);})
alert("sf");
$(this).children("a").stop(true,true).animate({"backgroundColor":"#111"}).end().siblings("a").anim

放置一个 alert("sf");看看第一次是不是弹出。有可能是异步请求导致的,改成同步的


$.ajax({
url : 'your url',
data:{name:value},
cache : false,
async : false,
type : "POST",
dataType : 'json/xml/html',
success : function (result){
do something....
}
});
  • 打赏
  • 举报
回复
执行文件超时?
OrganizeCity-model-get.php 超过30秒?
chrome右键审查元素->network,找到 OrganizeCity-model-get.php 查看一下。
猛仔不萌 2012-04-28
  • 打赏
  • 举报
回复
我在本地试了一下你的代码,可以的,是不是你的OrganizeCity-model-get.php文件里面的问题?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧