Javascript 使用ajax和特定目标函数设置间隔

Javascript 使用ajax和特定目标函数设置间隔,javascript,php,jquery,Javascript,Php,Jquery,chat.php setInterval(function(){ $.ajax({ type: "get", url: "chat.php", data: {fn: 'set_interval'}, success:function(data){ console.log(data); } }); }, 10000); 控制台显示:-未定义索引:fn… 我希望在控制台中完成

chat.php

setInterval(function(){
    $.ajax({
        type: "get",
        url: "chat.php",
        data: {fn: 'set_interval'}, 
        success:function(data){
            console.log(data);
        }
    });

}, 10000);
控制台显示:-
未定义索引:fn…


我希望在控制台中
完成

POST
更改为
GET
-

if(isset($_GET['fn'])){
    $fn = $_POST['fn'];
    $fn();
}

function set_interval(){
    echo 'done';
}

如果您想使用post,可以尝试将
类型更改为
“post”
,然后使用
if(isset($\u post['fn'])
,如果您想使用GET,请将
$\u POST
更改为
$\u GET
。您正在使用
GET
,但正在检查
$\u POST
。您正在检查GET put,并使用POSTMy journey重新设置值:)@qadenza
if(isset($_GET['fn'])){
    $fn = $_GET['fn'];
    $fn();
}