如何解决部署后,JS至PHP AJAX请求停止工作
因此,我正在使用AJAX将数据从PHP发送到JS>在localhost中,PHP回显的响应是我想要的数据以及HTML代码。但是当我部署到服务器时,它开始只返回HTML代码
PHP
if (isset($_REQUEST["getSectors"])) {
$getSectors = $_REQUEST["getSectors"];
if ($getSectors !== "") {
$sql = "SELECT setor_nome,id_setor FROM setores WHERE unidade_id = $getSectors";
$x = databaseRequestHandler($sql,$query);
$response = array();
foreach ($x as $y) {
array_push($response,[$y["setor_nome"],$y["id_setor"]]);
}
echo (json_encode($response));
}
}
JS
const unityChange = (unity) => {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const sectors = JSON.parse(this.responseText.split("<")[0]);
while (sectorDropdown[0].firstChild) {
sectorDropdown[0].removeChild(sectorDropdown[0].firstChild);
}
for (let i of sectors) {
// console.log(i);
var opt = document.createElement('option');
opt.value = i[1];
opt.innerHTML = i[0];
sectorDropdown[0].appendChild(opt);
}
}
};
xmlhttp.open("GET","gertecCovid.php?getSectors=" + unity,true);
xmlhttp.send();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。