这是我的代码,但它没有按预期工作。给定一个间隔,我想更新一个锚标记,但它永远不会更新。我怎样才能做到这一点?我对JQuery非常陌生,所以一个例子或指向我的东西,为我解释它将非常感激。
setInterval(function(){
$.ajax({
url:"flag.asp",
dataType:"text",
type:'POST',
success:function(flag){
if(flag != 'true'){
$("#test").attr({href:'somepath/somefile'});
$.ajax({
url:"context.asp",
data:{var1:var1},
type:'POST',
success:function(flag){
}
});
}
}
});
},8000);
答案 0 :(得分:0)
尝试添加到ajax选项> async = true
setInterval(function(){
$.ajax({
url:"flag.asp",
dataType:"text",
type:'POST',
async: true,
success:function(flag){
if(flag != 'true'){
$.ajax({
url:"context.asp",
data:{var1:var1},
type:'POST',
success:function(flag){
$("#test").attr({href:'somepath/somefile'});
}
});
}
}
});
},8000);
答案 1 :(得分:0)
我不太了解jquery,但我认为href属性不能像这样更新
$("#test").attr({href:'somepath/somefile'});
但它应该是
$("#test").attr('href','http://example.com');
查看您的更新代码,如下所示
setInterval(function(){
$.ajax({
url:"flag.asp",
dataType:"text",
type:'POST',
success:function(flag){
if(flag != 'true'){
$("#test").attr('href','http://example.com');
$.ajax({
url:"context.asp",
data:{var1:var1},
type:'POST',
success:function(flag){
}
});
}
}
});
},8000);