我只能得到getRating();
和getRatingText();
的功能更新,而无需重新加载网页。但其他功能getRatingText2();
和getRatingAvg();
将不会更新,直到我重新加载网页。JQuery更新问题?
如何在不重新加载我的网页的情况下更新所有功能?
这里是JQuery脚本。
$(document).ready(function() {
if($("#rating-text").length) {
getRatingText();
getRatingText2();
getRatingAvg();
getRating();
}
function getRatingText(){
$.ajax({
type: "GET",
url: "update.php",
data: "do=getavgrate",
cache: false,
async: false,
success: function(result) {
// add rating text
$("#rating-text").text(result);
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
function getRatingText2(){
$.ajax({
type: "GET",
url: "update.php",
data: "do=getavgrate2",
cache: false,
async: false,
success: function(result) {
$("#rating-text2").text(result);
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
function getRatingAvg(){
$.ajax({
type: "GET",
url: "update.php",
data: "do=getavgrate3",
cache: false,
async: false,
success: function(result) {
$("#grade-avg").text(result);
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
function getRating(){
$.ajax({
type: "GET",
url: "update.php",
data: "do=getrate",
cache: false,
async: false,
success: function(result) {
$("#current-rating").css({ width: "" + result + "%" });
$("#rating-text").text(getRatingText());
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
// link handler
$('#ratelinks li a').click(function(){
$.ajax({
type: "GET",
url: "update.php",
data: "rating="+$(this).text()+"&do=rate",
cache: false,
async: false,
success: function(result) {
$("#ratelinks").remove();
getRating();
},
error: function(result) {
alert("some error occured, please try again later");
}
});
});
});
我在哪里可以将此代码放入我的代码中我对JQuery相当陌生。 – pnut 2010-02-19 23:33:39
如果您希望getRatingText2()和getRatingAvg()在点击费率链接时进行更新,那么只需将它们放在$('#ratelinks li a')。click函数中即可。 – 2010-02-19 23:42:44
仍然无法正常工作。 – pnut 2010-02-19 23:46:08