我正在服务器端提交表单并在请求中设置用户对象。之后,我希望我的页面在 jquery ajax 的 success 方法之前刷新,以便可以反射(reflect)更新的值。有人可以帮助我吗?
下面是我的 jquery 代码:
function viewMemberProfile(userId){
document.getElementById("memberId").value=userId;
$.ajax({
type: "POST",
url:'viewMemberProfile.html',
cache: false,
data: $("#memberProfileForm").serialize(),
success: function (data) {
$("#memberProfileDiv").reveal({
animation : 'fade',
animationspeed : 400,
closeonbackgroundclick : true,
dismissmodalclass : 'close'
});
}
});
return false;
}
最佳答案
执行ajax请求然后重新加载整个页面有什么意义?您正在强制您的用户进行双重 http 请求。相反,我建议您编写一个 updateUserProfileDiv() 函数来执行您需要的所有更改。它的用法如下:
function viewMemberProfile(userId){
document.getElementById("memberId").value=userId;
$.ajax({
type: "POST",
url:'viewMemberProfile.html',
cache: false,
data: $("#memberProfileForm").serialize(),
success: function (data) {
//write new data to the profile panel
updateUserProfileDiv($("#memberProfileForm").serialize());
$("#memberProfileDiv").reveal({
animation : 'fade',
animationspeed : 400,
closeonbackgroundclick : true,
dismissmodalclass : 'close'
});
}
});
return false;
}
例如(我不知道你的数据):
function updateUserProfileDiv(data){
$('#username').html(data.username);
$('#birth').html(data.date_of_birth);
$('#city').html(data.city);
}
关于java - Jquery Ajax表单提交成功前如何刷新页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27738161/