bug^君 2016-03-22 13:50 采纳率: 25%
浏览 12

connect.send(窗体),不发送

sorry about my english. I have a problem with AJAX about one week, and can't solve it. I have Searched everywere. This is part of code of login.js function. I don't know why it don't work

..

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);

...

The path of ajax.php it's right, I put a message at the begining of ajax.php to check, but never execute.

ajax.php code...

<?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');  
 }
?>

Thanks in advance...

  • 写回答

1条回答 默认 最新

  • weixin_33725126 2016-03-22 15:08
    关注

    Change the first line of your PHP file to if (!empty($_POST)) {

    $_POST is never parsed to true, so your request always stops there. By using !empty you make sure there's a $_POST array, and that it's not empty.

    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思