【问题标题】:Redirection aftar a form submission using AJAX使用 AJAX 提交表单后重定向
【发布时间】:2014-02-11 16:22:40
【问题描述】:

我的网页上有一个表单,它是使用 AJAX 提交的。 将 SQL 查询发送到数据库后,我的页面上会显示一条错误消息以防出错。

否则,如果 SQL 查询成功,我想重定向到我网站上的另一个页面。 我已经使用 window.location.href 完成了数千次,但在这种情况下,会显示一个确认弹出窗口,要求成员确认操作。 如果会员点击“取消”,表格会一直显示,所以可以反复发送... 我找不到绕过此确认弹出窗口的任何解决方案。

有谁知道如何解决这个问题?

提前感谢您的帮助。

塑料第一

用于提交表单的函数:

function send_data(formname, callback, database_action)
{
    var xhr = getXMLHttpRequest();

    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
            callback(xhr.responseText, database_action);
        }
    };

    var oMessage = tinymce.get('message_content');
    var oMessageContent = oMessage.getContent();

    xhr.open("GET", "http://<?php echo $_SERVER['SERVER_NAME']; ?>/includes/updatedatabse.php?" + getquerystring(formname)+"&database_action="+database_action+"&message_content="+encodeURIComponent(oMessageContent), true);
    xhr.send(null);
}

以及相关的回调:

function updateMemberPage(result, database_action)
{
    var oErrorMessageDiv = document.getElementById('system-message-container');
    if(result)
    {
        window.top.window.scrollTo(0,0);

        // Redirect to the ads list page
        if(database_action == "update")
        {
            // Display an information message
            oErrorMessageDiv.innerHTML = "<div id='system-message' class='alert alert-success'>bla bla success</div>";
            window.location.href = "http://<?php echo $_SERVER['SERVER_NAME']; ?>/my-account";
        }

        // Reload the page to update the ads list
        else if(database_action == "insert")
        {
            // Display an information message
            oErrorMessageDiv.innerHTML = "<div id='system-message' class='alert alert-success'>bla bla success</div>";
            location.reload();
        }
    }
    else
    {
        // Display an error message
        oErrorMessageDiv.innerHTML = "<div id='system-message' class='alert alert-error'>bla bla error</div>";
    }
    window.top.window.scrollTo(0,0);
}

【问题讨论】:

    标签: javascript ajax redirect popup confirm


    【解决方案1】:

    问题解决了:)

    我的表单中有一个 tinyMCE 对象,它被配置为在卸载事件时显示警告消息,以免丢失其内容(例如在页面刷新时)。

    我只需要修改这个设置,问题就解决了。

    【讨论】:

      猜你喜欢
      • 2014-01-25
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      相关资源
      最近更新 更多