我有一个为每个比赛的现场得分结果的页面,该页面有两个部分,向上部分,其中有现场结果和比赛信息和向下部分,其中有评论区。当我发表评论并单击submit the page refresh并向上转到信息部分时,我想添加评论并刷新页面,然后向下转到评论所在的位置(而不是向上)。我的注释框代码是:
$("#section_bar").after('<textarea rows="4" cols="50" id="" class="comment_area" name="reply_area" ></textarea><a class="comment button small black" href="#" id="reply_'+match_id+'"><span>submit</span></a>');
$("#reply_"+match_id).live('click',function(){
text_area_value = $('textarea').val();
$.ajax({
type: "POST",
url: 'comment_proxy.php',
data:{id:match_id, user_id:user_id, reply:text_area_value, date:today1, time:time},
dataType: "json",
success: function(data)
{
location.reload();
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
/*alert(XMLHttpRequest);
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);*/
}
});
});我的问题是:有没有哪行代码可以添加到location.reload()之后,强制页面提交并刷新,然后停留在提交之前的相同位置或返回到提交之前的相同位置?
发布于 2014-03-02 19:51:32
在不知道数据结果是如何格式化的情况下,您可以像这样添加来自帖子的结果,而不是重新加载您的页面location.reload();:
使用javascript (因为我不是jQuery开发人员)
success: function(data)
{
// add the "data" to your div
document.getElementById("div_with_posts_id").innerHTML += data;
// maybe clear/reset the form here ?
},https://stackoverflow.com/questions/22127009
复制相似问题