如何在ajax中使用setTimeout传递下一页的参数?

时间:2017-11-02 06:40:41

标签: javascript settimeout

我想使用ajax将值传递到setTimeout中的下一页。

实际代码是

setTimeout(' window.location.href ="signin.php";',4000);

但是我想把它写成

 setTimeout(' window.location.href ="signin.php?success";',4000);

因此它不起作用。

4 个答案:

答案 0 :(得分:2)

将此代码用于此功能。

setTimeout(function(){ 
       window.location = "signin.php?success=y";
    }, 
4000);

答案 1 :(得分:0)

//we store out timerIdhere
var timeOutId = 0;
//we define our function and STORE it in a var
var ajaxFn = function () {
        $.ajax({
            url: '/echo/html/',
            success: function (response) {
                if (response == 'True') {//YAYA
                    clearTimeout(timeOutId);//stop the timeout
                } else {//Fail check?
                    timeOutId = setTimeout(ajaxFn, 10000);//set the timeout again
                    console.log("call");//check if this is running
                    //you should see this on jsfiddle
                    // since the response there is just an empty string
                }
            }
        });
}
ajaxFn();//we CALL the function we stored 
//or you wanna wait 10 secs before your first call? 
//use THIS line instead
timeOutId = setTimeout(ajaxFn, 10000);

或者你可以

setTimeout(function(){ 
       window.location = "somepage.php?success=y";
       //send id with page
    }, 
1000);

By :: https://stackoverflow.com/users/368070/gideon

答案 2 :(得分:0)

你可以传递参数如下

setTimeout(function(){ 
    window.location = "signin.php?success=true";
}, 3000);

这会有效!

答案 3 :(得分:0)

url中您必须传递参数,因此您需要?parameter=value

所以在链接后添加?paramenter并在参数设置后设置其值=value

setTimeout('window.location.href ="signin.php?val=success";',4000);