连接发送(表单),不要发送


connect.send (form) , don't send

对不起我的英语。我在大约一周内遇到了 AJAX 问题,无法解决。我搜索过每一个。这是登录.js函数代码的一部分。我不知道为什么它不起作用

..

connect.open("POST","ajax.php?mode=login",true);
connect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
window.alert(form); //here I see the window,with the data form ok
connect.send(form);

ajax的路径.php没错,我在ajax的开头放了一条消息.php检查,但从不执行。

Ajax.php代码...

<?php
if($_POST)
{
switch (isset($_GET['mode']) ? $_GET['mode'] : null)  
 {        
case 'login':             
echo "login case";        
  break;       
default:           
  header('location: index.php');
 break;        
}
} 
else
{    
  header('location: index.php');  
 }
?>

提前感谢...

将 PHP 文件的第一行更改为 if (!empty($_POST)) {

$_POST 永远不会解析为 true ,因此您的请求始终止步于此。通过使用!empty可以确保有一个 $_POST 数组,并且它不为空。