java - Jquery Ajax表单提交成功前如何刷新页面?

标签 java jquery ajax spring-mvc

我正在服务器端提交表单并在请求中设置用户对象。之后,我希望我的页面在 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/

相关文章:

jquery - 制作链接 :active

php - 制作 'mobile/cell' 版本的 PHP/Javascript 网站?

java - JavaME 函数帮助

java - 使用 maven 创建 JVM 时出错

jquery - jCarousel自定义开始位置

javascript - 不能 float Div

java - 在 -XX :OnOutOfMemoryError using shell script gives: Unrecognized option: -9 上重新启动进程

Java - 将 int 更改为 ascii

java - 如何通过 BOT 的 Ajax 调用进行保护?

javascript - jQuery 简单的 ajax 请求不起作用