Browser message after AJAX request

Asked

Viewed 773 times

3

I have an ajax request responsible for sending a file to Servlet, it is performing the process correctly. But when I update the page the following message is displayed by the browser (When I give a F5):

The page you are looking for used inserted information. Going back to this page can cause all actions performed to be rethought. Wishes to Continue ?

I don’t want this message to appear to my users.

Ajax request:

$(document).ready(function($) {
    $("#formAv").submit(function(event) {
        var dados = new FormData(this);
        var url = "Avatar";
        $.ajax({
            url: url,
            type: 'GET',
            data: dados,
            mimeType: "multipart/form-data",
            contentType: false,
            cache: false,
            processData: false,
        });
    });
});

NOTE: The message is from the browser itself, I tried to clear the form after sending but did not resolve.

  • If you’re doing Ubmit via ajax you should have event.preventDefault(); within that function, before var dados for example.

  • 1

    Thanks for the answer worked! Just remembering that the type is POST, I was wrong to paste the code.

1 answer

2

This warning that the browser gives happens only when you submit a form via the HTML API. That is, using the <form action="". Once you are using ajax, you should unsubscribe the form via HTML API and submit, as you are doing via ajax.

To cancel the natural action you can do with event.preventDefault(). Then your code could be like this:

$(document).ready(function($) {
    $("#formAv").submit(function(event) {
        event.preventDefault();
        var dados = new FormData(this);
        var url = "Avatar";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.