How do I redirect to another webpage?

Dev
Dev
14 Points
7 Posts

I'm trying following ajax code but no success:

$.ajax({
    url: 'https://www.linkedin.com/oauth/v2/authorization?response_type=code',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    type: "GET",
    dataType: "json",
    data: {
    },
    success: function (result) {
        console.log(result);
    },
    error: function () {
        console.log("error");
    }
});

How can I redirect the user from one page to another using jQuery or pure JavaScript?

Views: 432
Total Answered: 1
Total Marked As Answer: 1
Posted On: 01-Jan-2021 04:44

Share:   fb twitter linkedin
Answers
beginer
beginer
294 Points
82 Posts
         

Use either location.href or location.replace:

// Simulate a mouse click:
window.location.href = "https://www.niceonecode.com";

// Simulate an HTTP redirect:
window.location.replace("https://www.niceonecode.com");

replace() removes the URL of the current document from the document history, it means that it is not possible to use the "back" button to navigate back to the original page.

Posted On: 06-Jan-2021 07:01
 Log In to Chat