AJAX调用+ JQuery Dialog标题动态变化

时间:2010-06-03 06:55:22

标签: jquery ajax jsp

我有一个AJAX调用加载一个Dialog页面,现在根据AJAX调用返回的数据内容,我想更改Window的标题,我该怎么做。

以下是代码片段:

    var divid = "brHistoryForm";
    var url = "getRestoreFiles.action?profileName="+profileName;

    // Create xmlHttp
    var xmlHttp = AJAX();

    // The code...
    xmlHttp.onreadystatechange=function(){
        if(xmlHttp.readyState==4){
            document.getElementById(divid).innerHTML=xmlHttp.responseText;
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);

    $('#brHistoryForm').dialog('open');
    jQuery('#brHistoryForm').focus();

document.getElementById('pageTitle').innerHTML = "<h2>"+profileName+" - B&R History</h2>"

这里'pageTitle'是一个div。当我运行上面的代码时,它打开一个对话框窗口,操作被重定向到一个jsp页面,该页面被加载到div中。它工作正常,但标题没有设置:(。

我尝试在重定向的jsp页面中设置标题,但它也不起作用。

以下是该JSP页面的代码:

   <%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>B&R History</title>
    </head>
    <body>
         <table style="width: 100%">
            <tr>
                 <td style="width: 40%">
                    <div id="pageTitle">
                        <h2>B&R History</h2>
                    </div>
                 </td>
             </tr>
         </table>

         <table id="diskTable" cellpadding="0" cellspacing="0" border="1" class="display">
             <thead>
                 <tr>
                     <th>Select</th><th>Operation</th>
                     <th>Source</th><th>Destination</th>
                     <th>Status</th><th>Start Time</th><th>End Time</th>
                 </tr>
             </thead>
             <tfoot></tfoot>
             <tbody>
                 <s:iterator value="restoreFileList">
                     <tr>
                         <td>
                            <s:if test="%{status.equals('Finished')}">
                                <input onClick="loadRestoreForm('<s:property value="name"/>', '<s:property value="to_path"/>', '<s:property value="status"/>')" type="radio" name='chk' id="chk" value="<s:property value='id'/>,<s:property value="status"/>" >
                            </s:if>
                            <s:else>
                                 <input type="radio" name='chk' id="chk" value="<s:property value='id'/>,<s:property value="status"/>" disabled>
                            </s:else>
                         </td>
                         <td>
                            <s:if test="%{br_type == 0}">
                                Backup
                            </s:if>
                            <s:else>
                                Restore
                            </s:else>
                         </td>
                         <td><s:property value="from_path"/></td>
                         <td><s:property value="to_path"/></td>
                         <td><s:property value="status"/></td>
                         <td><s:property value="start_time"/></td>
                         <td><s:property value="end_time"/></td>
                     </tr>
                 </s:iterator>
             </tbody>
         </table>
    </body>
</html>

任何帮助都将不胜感激。

2 个答案:

答案 0 :(得分:1)

// The code...
xmlHttp.onreadystatechange=function(){
    if(xmlHttp.readyState==4){
        document.getElementById(divid).innerHTML=xmlHttp.responseText;
        document.getElementById('pageTitle').innerHTML = "<h2>"+profileName+" - B&R History</h2>";
    }
}

答案 1 :(得分:0)

javascript和jquery

function changewindow(url,userdata){
$.ajax({
    type: "POST",
    url: url,
    data: userdata,
    dataType: "html",
    success: function(html){                
        $("#bodycontent").html(html);
    },
    error: function(html){
        alert(html);
    }
});}
相关问题