使用AJAX运行的PHP文件

I have a php file that automatically inserts and another one that updates my database, i need a script that will allow me to run these 2 file on background without me having to click any buttons.

Try to do it with JS interval

setInterval(function(){ /* AJAX request */ }, 3000);

Since cronjob was mentioned for scheduled tasks, it has advantages over infinite loop like that, however questioner mentioned AJAX so this is AJAX solution to repeatable tasks, it of course will only run if client runs the application and is better solution for client based functionality like checking new messages, detecting user status updates or even chat, so simplified it will look like this:

$( document ).ready(function() {
    setInterval(function(){
       $.ajax({
            type: "post",
            url: "/myTasks.php",
            cache: false,
            data: {/* Some data to send to server */},
            beforeSend: function () {
               /* Do some stuff before sending */
            },
            success: function (RecievedData) {
                /* Do some stuff after recieving */
            },
            error: function (RecievedData, textStatus) {
                //console.log(JSON.stringify(RecievedData));
                //console.log(textStatus);
            },
            complete: function (RecievedData) {
               /* Do some stuff regardless success or fail */
            }
        });
    };    
}, 1000);// one second interval
});

I'm using Jquery here just for the sake of example

you must use the crontab ... You can access (from linux) the file listing all your cron tasks with the command:

crontab -l

To edit this file just do:

crontab -e

For example, you can add something like this to this file: 0 2 * * * php -f /folder/file_insert.php