0
我有一个函数发送一个post请求到php网站。我通过简单地改变变量的大小来获得2种不同的行为。问题中的变量是'action'变量,并且被设置为“deleteIndexMain”或“deleteIndexmain”如果操作变量设置为“deleteIndexmain”,我会弹出一个显示php返回的html的弹出窗口。如果我将变量设置为“deleteIndexMain”,则不会弹出。 (这意味着它似乎是一个JavaScript的问题AJAX的奇怪Javascript/PHP行为
这里是java脚本代码:
function deleteMe(v,r)
{
if(confirm("Are you sure"))
{
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function()
{
if(xhttp.readyState == 4 && xhttp.status == 200)
{
alert(xhttp.responseText);
document.getElementById("indexmaintable").deleteRow(r);
}
};
xhttp.open("POST", "includes/control.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("action=deleteIndexMain&file="+v);
}
}
这里是PHP代码:
<?php
//Todo make sure to authenticate!
session_start();
require_once("config.php");
function deleteIndexMain($file)
{
unlink($file);
$query = 'DELETE FROM indexmain WHERE linklocation="'.$file.'"';
$db->query($query);
}
print_r($_POST);
if(isset($_POST) && $_POST['action'] == "deleteIndexMain")
{
echo 'Deleting '.$_POST['file'];
deleteIndexMain($_POST['file']);
}
?>
在JS和PHP中都有“deleteIndexMain”。当你改变大写字母时,你是否在两个文件中改变它?如果没有,我认为这是你的答案。 – cuniculus
没有提示框可能表示PHP错误,因为AJAX请求没有返回200.您是否可以检查在Chrome/Safari的网络时间轴中是否获得500deg? – cuniculus
ID,变量和值,例如'$ _POST ['action'] ==“deleteIndexMain”中的'deleteIndexMain'是区分大小写的/唯一的; *故事结局*。 I.e .:'$ dog'和'$ Dog'是两个不同的动物,'#cat'和'#Cat'也是。这适用于大多数或所有编程/编码语言。 –