bsuart
bsuart

Reputation: 361

Open new html page instead current page(Ajax. JQuery)

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?

Upvotes: 1

Views: 2291

Answers (2)

bobby kc
bobby kc

Reputation: 26

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

Upvotes: 0

Piyin
Piyin

Reputation: 1834

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

Upvotes: 1

Related Questions