Question

I have a form on my web page, which is submitted using AJAX. Once the SQL query has been sent to the database, an error message is displayed on my page in case of error.

Otherwise, if the SQL query was successfull, I want to redirect to another page on my site. I've done this thousands of time, using window.location.href, but in this case, a confirmation popup is displayed, asking the member to confirm the action. If the member clicks on "cancel", the form is always displayed, so it can be send again and again... I can't find any solution to bypass this confirmation popup.

Does anyone know how to fix this issue ?

Thanks in advance for your help.

plastic1st

Function used to submit the form :

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);
}

and the associated callback :

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);
}

No correct solution

OTHER TIPS

Problem solved :)

I have a tinyMCE object in my form, and it was configured to display a warning message on unload events, in order not to lose its content (for example on a page refresh).

I only had to modify this setting, and the problem was fixed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top