从 js 执行 php 文件更多次

Execute php file from js more times

在javascript中我有一个执行php函数的代码:

var oReq = new XMLHttpRequest();

oReq.onload = function getData() {
 var result = this.responseText;
 result = JSON.parse(result);
 console.log(result);
};

oReq.open("get", "../my_php/index.php", true);

const startIt = () => {
 oReq.send();
};

HTML:

<button class="btn btn-primary" onclick="startIt()" type="button" >Run</button>

这段代码工作正常,但只有一次,然后网站需要刷新。否则显示错误:
InvalidStateError: 对象处于无效状态。

谢谢大家的宝贵意见
我将 oReq.open("get", "../my_php/index.php", true); 移动到函数 startIt 并且一切正常

var oReq = new XMLHttpRequest();

oReq.onload = function getData() {
 var result = this.responseText;
 result = JSON.parse(result);
 console.log(result);
};


const startIt = () => {
 oReq.open("get", "../my_php/index.php", true);
 oReq.send();
};