相关疑难解决方法(0)

POST后重新加载浏览器窗口,而不提示用户重新发送POST数据

当用户访问我的网站时,每个页面上都有一个"登录"链接.单击此按钮可使用一些JavaScript显示覆盖窗口,提示用户提供其凭据.输入这些凭证后,将对Web服务器进行Ajax调用以验证它们; 如果它们有效,则会发回验证票证cookie并重新加载页面,以便显示特定于已验证用户或(现在)当前登录用户的页面上的任何内容.

我正在使用以下脚本完成页面重新加载:

window.location.reload();
Run Code Online (Sandbox Code Playgroud)

这非常适用于通过GET请求(绝大多数)加载的页面,但有些页面使用回发表单.因此,如果用户转到其中一个页面,执行回发,然后选择登录,则在window.location.reload()脚本运行时会通过对话框提示是否要重新提交POST正文.

重新提交POST正文对话框

我想绕过这个我可以告诉浏览器重新加载页面,所以我试过:

window.location.href = window.location.href;
Run Code Online (Sandbox Code Playgroud)

但浏览器不会对上述语句采取任何操作,我认为是因为它认为新URL与旧URL相同.如果我将以上内容更改为:

window.location.href = window.location.pathname;
Run Code Online (Sandbox Code Playgroud)

它重新加载页面,但我丢失了任何查询字符串参数.

我当前的解决方法已经足够了,但并不漂亮 - 简而言之,我将查询字符串参数添加到当前window.location.href值,然后window.location.href通过调用将其分配回来reloadPage("justLoggedIn"),其中reloadPage函数是:

function reloadPage(querystringTackon) {
    var currentUrl = window.location.href;

    if (querystringTackon != null && querystringTackon.length > 0 && currentUrl.indexOf(querystringTackon) < 0) {
        if (currentUrl.indexOf("?") < 0)
            currentUrl += "?" + querystringTackon;
        else
            currentUrl += "&" + querystringTackon;
    }

    window.location.href = currentUrl;
}
Run Code Online (Sandbox Code Playgroud)

这可行,但它会导致URL www.example.com/SomeFolder/SomePage.aspx?justLoggedIn,这似乎很俗气.

在JavaScript中是否有办法让它进行GET重新加载而不提示用户重新提交POST数据?我需要确保任何现有的查询字符串参数都不会丢失.

javascript

54
推荐指数
5
解决办法
11万
查看次数

如何在上传primefaces后重新加载jsf页面?

在primefaces上传后,重新加载jsf页面有什么用?

我尝试使用javascript oncomplete="javascript:window.location.reload()",但它不起作用:

XHTML:

<h:form>
    <p:messages showDetail="true"/>  
    <p:fileUpload fileUploadListener="#{revistauploadBean.upload}"
                  mode="advanced" dragDropSupport="false" merge="true"  
                  uploadLabel="Enviar" cancelLabel="Cancelar"
                  oncomplete="javascript:window.location.reload()"
                  label="Procurar PDF" sizeLimit="1000000000" fileLimit="3"
                  allowTypes="/(\.|\/)(pdf)$/" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

豆:

public void upload(FileUploadEvent event) throws SQLException {  
    LoginAuthentication user = new LoginAuthentication();
    FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() 
        + " is uploaded.");  
    FacesContext.getCurrentInstance().addMessage(null, msg);
    // Do what you want with the file        
    try {
        copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
        ConectaBanco mysql = new ConectaBanco();
        mysql.insere("INSERT INTO edicoes VALUES (NULL, '" 
            + mysql.pegaIDrev(user.getNome()) 
            + "', NULL, NULL, NULL, NULL, …
Run Code Online (Sandbox Code Playgroud)

javascript jsf file-upload primefaces jsf-2

5
推荐指数
1
解决办法
1万
查看次数

关闭p:对话框后如何刷新页面

我有以下对话框:

<h:form id="r1">
  <p:commandButton value="Basic" type="button" onclick="PF('dlg1').show();" />
  <p:dialog header="Basic Dialog" widgetVar="dlg1">
    <h:outputText id="test" value="Welcome to PrimeFaces" />
  </p:dialog>
</h:form>
Run Code Online (Sandbox Code Playgroud)

关闭对话框后如何刷新JSF页面?

jsf dialog primefaces page-refresh

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×2

jsf ×2

primefaces ×2

dialog ×1

file-upload ×1

jsf-2 ×1

page-refresh ×1