将重定向URL链接添加到JS函数

Add Redirect URL link to JS Function

本文关键字:JS 函数 添加 链接 重定向 URL      更新时间:2023-09-26

如何在下面的代码中添加重定向URL链接到JS函数(示例表单操作到:session.php)。我尝试了另一种方式的代码,但它仍然无法工作。

$(document).ready(function() {
    $("#submit_butt").click(function() {
        var conf = {
            frequency: 5000,
            spread: 5,
            duration: 600
        };
        /* do your AJAX call and processing here...
        ....
        ....
        */
        // this is the call we make when the AJAX callback function indicates a login failure 
        $("#login").vibrate(conf);
        // let's also display a notification
        if($("#errormsg").text() == "")
            $("#loginform").append('<p id="errormsg">Invalid username or password!</p>');       
        // clear the fields to discourage brute forcing :)
        $("#password").val("");
        document.forms['login_form'].elements['username'].focus();
    });
});

你可以试试这个

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

https://developer.mozilla.org/en-US/docs/DOM/window.location

参考:如何在JavaScript/jQuery中重定向到另一个网页?

您可以使用它。。

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

您可以尝试

 <script>
 function name(){
    window.location ='abc.php';
 }
 </script>

您可以通过破解javascript 中的php代码

$(document).ready(function()
{
    <?php 
       someFunction();
    ?>
});

但前提是javascript位于php文件中,因此php可以对其进行处理。因此,如果您链接到一个需要更改为.php 的.js文件