這是我寫的第一個php程序。我的Ajax請求看起來沒問題,我的狀態爲200,但沒有得到任何迴應。爲什麼這個簡單的PHP沒有返回響應?
<?php
class Employee{
private $fn;
private $ln;
private $dpt;
private $ID;
}
function newEmployee(){
$employee = new Employee();
$fn = $_POST['firstname'];
$ln = $_POST['lastname'];
$dpt = $_POST['department'];
$id = sprintf('%08d', $GLOBALS['$ID']);
$GLOBALS['$ID'] = $GLOBALS['$ID'] + 1;
echo "First Name: $employee\nLast Name: $ln\nDepartment: $dpt\nID: $id";
$employee -> fn = $_POST['firstname'];
$employee -> ln = $_POST['lastname'];
$employee -> dpt = $_POST['department'];
$GLOBALS['$employeeArray'][]= $employee;
$GLOBALS['$numOfEmployees'] = $GLOBALS['$numOfEmployees'] + 1;
$numemployees = $GLOBALS['$numOfEmployees'];
echo "First Name: $employee\nLast Name: $ln\nDepartment: $dpt\nID: $id\nNumber of Employees: $numemployees";
}
if(isset($_POST['submit']))
{
newEmployee();
}
$employeeArray = array();
$ID = 0;
$numOfEmployees = 0;
?>
字面上我的第一個PHP程序,所以我肯定這是愚蠢的。因爲該行的
這就像你的接縫不會在您的文章發送一個「提交」值,$ _ POST [「提交」]是不是isset – MacBooc
謝謝你會建議?將它添加到ajax或將該條件更改爲其他內容? – Zachscs
對我來說並不是真的最好練習你的問題,兩者都應該工作 – MacBooc