0

假设我在浏览器中键入一个 URL (http://localhost:8080/Proj/page),然后我得到一个页面,其中有菜单和 iframe。单击菜单时,我通过发布一些数据并获取 HTML 文档作为响应来向服务器发出 ajax 请求。我正在使用 javascript 将 HTML 文档手动更新为 iframe。{这背后的原因是 URL 有一个查询参数,我想将它发布到服务器而不是 GET,因此我没有更改 iframe src}

前任:

<a href="#" onClick="frameopen('helloWOrld.html?a=bc&d=ef')">menu</a>;
function frameopen(url) {
    var dataToSend = getQueryParameterFrmUrl(url);//got data in form of Object
    var urlWithoutQUeryParam = getUrlWithoutQueryParam(url);//got url without query parameter
    positionThrobber("section16_contentframe");//add the throbber
    //perform POST using ajax
    $.ajax({
        url: urlWithoutQUeryParam,
        data: dataToSend,
        type: 'POST',
        success: function (serverResponse) {
            //server response came write this to iframe
            removeThrobber();
            var ifrm = document.getElementById('contentframe');
            ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
            ifrm.document.open();
            ifrm.document.write(serverResponse);//server response written
            ifrm.document.close();
        },
        error: function (jqXHR, textStatus, errorThrown) {
            removeThrobber();
            alert("Ajax Request Failed!Text Status:" + textStatus + ",errorThrown:" + errorThrown);
        }

    });

}

现在 iframe 由服务器响应填充,它包含一个表单。

<iframe src="">
<html><body>
<form name="inboxSearchForm" id="inboxSearchForm" commandName="userQueueFilter" action="${pageContext.request.contextPath}/inbox/search" method="post">
<a href="#" id="nextPage" onclick="pageJump(document.getElementById('pageNum').value,'up') ">Next ></a>
</form>
</body></html>
</iframe>

iframe 中有一个链接(称为 Next),它使用 javascript 提交表单

document.getElementById('inboxSearchForm').submit();

问题是当我单击链接 Next..iframe 加载了 URL 内容,(http://localhost:8080/Proj/page即 iframe 现在存储整个页面,即菜单和 iframe,它是递归的..谁能告诉我可能是什么原因..我希望 iframe 成为从 URL 刷新,/inbox/search而不是从浏览器中的 URL 刷新..这种行为没有反映在 IE 面临的 mozilla 问题中:(

4

1 回答 1

0

首先,IFrame 页面将永远无法联系到主页。

建议: 不要为此目的使用 iframe。如果您想从其他页面获取一些内容,请使用jquery 的$.load

但在您的情况下,我建议您使用div相当 iframe 制作表单。代码可能看起来与一些细微的变化相同。

于 2012-12-28T10:12:48.100 回答