我正在用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