我只能得到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