Home > front end >  Redirecting to new page after closing AJAX popup window
Redirecting to new page after closing AJAX popup window

Time:07-02

How to redirecting to a new page after closing popup window with code like this:

     send_ajax_formdata("POST","{{ url('/url') }}", {}, fData, {})
     .then((resp) => {
        if(resp[0].valid == "true") {
             success_alert(resp[0].message);
        }else {
            warning_alert(resp[0].message);
        }

        elem.removeClass("disabled");
        elem.html(text);
    })
    .catch((err) => {
        danger_alert(err.message);
        elem.removeClass("disabled");
        elem.html(text);
    })

When button close clicked then it will close the popup window with script disabled removeClass. But instead back to page where that popup window page exist, I want to redirecting it to a new page. How to do that?

CodePudding user response:

you use window location to redirect to url in jquery.

window.location.href = '/'   resp.data.redirect_path;

Here, resp.data.redirect_path is your redirect url variable, you can also use solid url to any page like:

window.location.href = "http://www.google.com";

CodePudding user response:

You can use location.replace

window.location.replace(resp.href);

// let say the href is "https://stackoverflow.com/"
window.location.replace("https://stackoverflow.com/");
  • Related