1

I have ajax request:

 function sendData(user) {
        $.ajax({
            type: 'POST',
            url: '/user-check',
            data: JSON.stringify(user),
            headers: {
                'Accept': 'application/text',
                'Content-Type': 'application/json',
            },
            dataType: 'text',
            success : function(completeHtmlPage) {
                alert("Success");
                var pageName = completeHtmlPage + ".html";
                window.open(pageName);

            },
            error: function() {

                alert('Error authorization');

            }
        });
    }

I want to open new page with name completeHtmlPage + ".html". How to open new page instead current page?

bsuart
  • 351
  • 1
  • 4
  • 24
  • Do you mean in a new browser window? – Erik Philips Nov 07 '17 at 17:11
  • 1
    Possible duplicate of [Open a URL in a new tab (and not a new window) using JavaScript](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript) – Sterling Archer Nov 07 '17 at 17:12
  • Does it have to be in another window? Because if it's just a redirection you could use: `document.location.href = pageName;` rather than `window.open(pageName);` – Piyin Nov 07 '17 at 17:12
  • It looks like your code should already do what you're saying you want it to do (assuming the AJAX request is returning a file name). Is it not working as expected? – Daniel Beck Nov 07 '17 at 17:15
  • @ErikPhilips No, in current browser window – bsuart Nov 07 '17 at 17:23
  • 1
    @Piyin in the current browser window – bsuart Nov 07 '17 at 17:23
  • Possible duplicate of [How to redirect to another webpage?](https://stackoverflow.com/questions/503093/how-to-redirect-to-another-webpage) – Erik Philips Nov 07 '17 at 17:24

2 Answers2

1

Since you want to do a redirection on the same page, you could change your success block to:

success : function(completeHtmlPage) {
    alert("Success");
    var pageName = completeHtmlPage + ".html";
    document.location.href = pageName;
},
Piyin
  • 1,823
  • 1
  • 16
  • 23
0

Yes use location.href = (relative/or absolute)

bobby kc
  • 26
  • 2