首先在10秒内调用javascript函数,然后每25秒调用一次[jQuery]

Sau*_*abh 1 javascript jquery

这是我的代码:

setInterval(function() {
    $.ajax({
        type: "GET",
        url: "someurl",
        dataType: "json",
        success: function(data) {
          //Some code
        }
    });
}, 25 * 1000);
Run Code Online (Sandbox Code Playgroud)

上面的代码每25秒调用一次ajax方法.但是我第一次需要它在10秒内调用它,然后每25秒调用一次.

所以我跟着这个

并将我的代码更改为以下内容:

setTimeout(function() {
    setInterval(function() {
        $.ajax({
            type: "GET",
            url: "someurl",
            dataType: "json",
            success: function(data) {
              //Some code
            }
        });
    }, 25 * 1000);
}, 10 * 1000);
Run Code Online (Sandbox Code Playgroud)

但它似乎仍然没有奏效.

use*_*559 5

setTimeout(function() {
    function doit() {
        console.log("HERE");
    }
    doit(); // It's already been 10 seconds, so run it now
    setInterval(doit, 25 * 1000); // Run it every 25 seconds from here on out
}, 10 * 1000);
Run Code Online (Sandbox Code Playgroud)