我正在用jQuery更新我的數據庫.click()
,然後調用我的AJAX;我的問題是一旦SQL運行了什麼是刷新頁面上的內容的最佳方式,所以我將能夠再次執行上一個操作,目前我使用的是window.location.reload(true);
,但我不喜歡這種方法,因爲我不喜歡「噸要在頁面重新加載所有我要的是我用更新它是相匹配的數據庫字段的AJAX成功後的元素有關的內容成功後jQuery AJAX刷新頁面內容
這裏是我的jQuery:
$(document).ready(function(){
$("span[class*='star']").click(function(){
var data = $(this).data('object');
$.ajax({
type: "POST",
data: {art_id:data.art_id,art_featured:data.art_featured},
url: "ajax-feature.php",
success: function(data){
if(data == false) {
window.location.reload(true);
} else {
window.location.reload(true);
}
}
});
console.log(data.art_featured);
});
});
編號:
我需要art_featured
更新的類.star
或.star-color
這取決於一個art_featured
的價值的時候,基本上是在以往任何時候我呼應了art_featured
我需要重新加載,一旦Ajax是成功的。
編輯:
$("span[class*='star']").click(function(){
var data = $(this).data('object');
var $this = $(this); //add this line right after the above
$.ajax({
type: "POST",
data: {art_id:data.art_id,art_featured:data.art_featured},
url: "ajax-feature.php",
success:function(art_featured){
//remember $this = $(this) from earlier? we leverage it here
$this.data('object', $.extend($this.data('object')),{
art_featured: art_featured
});
}
});
console.log(data.art_featured);
});
什麼是需要更新的HTML元素?我們可以看到它嗎?您還可以概述哪些元素特別需要更新,以便我們可以更好地解決手頭的問題? – Ohgodwhy 2013-03-26 05:47:33
您可以使用json響應並從匹配的json響應中替換舊的DOM html或值。 – 2013-03-26 05:51:03
@Ohgodwhy謝謝,我只是更新了我的帖子。 – 2013-03-26 05:51:47