我试图让下面的代码只显示在特定页面上,但是当我点击某些页面,比如主页或者其他任何不使用这段代码的页面时,我会得到如下警告(“发生了一些错误,请稍后再试”);。JQuery警报问题?
如何在不使用此JQuery代码的页面上显示警告框并仍然有代码工作?
我正在使用JQuery,PHP & MySQL。
这里是JQuery代码。
$(document).ready(function() {
// get average rating
getRatingText();
// get average rating function
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");
}
});
}
// get current rating
getRating();
// get rating function
function getRating(){
$.ajax({
type: "GET",
url: "../../../update.php",
data: "do=getrate",
cache: false,
async: false,
success: function(result) {
// apply star rating to element dynamically
$("#current-rating").css({ width: "" + result + "%" });
// add rating text dynamically
$("#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) {
// remove #ratelinks element to prevent another rate
$("#ratelinks").remove();
// get rating after click
getRating();
},
error: function(result) {
alert("some error occured, please try again later");
}
});
});
});
是否有一个PHP代码可以做到这一点,因为我在我的PHP包含这个代码。 – gReEdY 2010-02-18 22:15:57