Form that makes browser redirect when accessed by either a regular form submit or an Ajax request - is this possible?

后端 未结 8 1616
孤城傲影
孤城傲影 2021-01-06 08:22

I have a web page with a form. When the user submits the form, I want the server to make the browser redirect to a different page from the form action. Right now, I am doing

8条回答
  •  灰色年华
    2021-01-06 09:00

    Here is another option although you will need to do some cross browser tests:

    complete: function(request) {
        if(request.status == 200) {
            var doc = document.open(request.getResponseHeader('Content-Type'));
            doc.write(request.responseText);
            doc.close();
        }
    }
    

    Major drawbacks: URL in address bar doesn't change; could mess with back button/history

    Although I think @crescentfresh's idea is the way to go

提交回复
热议问题