使用jquery刷新特定的div

时间:2014-06-10 07:32:32

标签: jquery html ajax jsp

我收到回复后想要使用ajax调用刷新特定的div标签

<script>
    $(document).ready(function() {

        $('#add-new-department').submit(function(event) {
            var departmentname = $('#departmentname').val();


            $.ajax({
                url : $("#add-new-department").attr("action"),
                type : "POST",
                data : "departmentname="+departmentname,

                success : function(response) {
                    $('#status').html(response);
                    $('#departmentname').val('');
                    $('#department').load("");   
                }
            });

            event.preventDefault();
        });

    });
</script>

我想在jsp页面中更新消息

 <div id="department">Department Updated : <% new Date(); %> </div>

我的要求是在刷新 div标记 像

 $('#department').refresh(); 

3 个答案:

答案 0 :(得分:1)

使用html()而不是load()喜欢,

$('#department').html("Department Updated : "+new Date());

答案 1 :(得分:1)

$.ajax({
  url : $("#add-new-department").attr("action"),
  type : "POST",
  data : "departmentname="+departmentname,

  success : function(response) {
     $('#status').html(response);
     $('#departmentname').val('');
     $('#department').html('Department Updated: ' + new Date());   
  }
});

答案 2 :(得分:0)

使用此功能,编写您的页面名称而不是content.php

$('#department').load('content.php')