【发布时间】:2013-09-28 03:47:50
【问题描述】:
我的网站上有一个输入字段。当用户开始在此输入字段中输入他们学校的名称时,下面的 <select> 标签应该会自动执行以下操作:
1. 访问我的 JavaScript 文件(这可行)
2. JavaScript 文件应该检索 <input> 的值并将其传递给 PHP 文件(这可行)
3. PHP 文件应该接收到已发送的字符串(这可行)
4. PHP 文件应该在FetchSchool 类中创建 3 个变量:
5. 第一个变量是_string,它将保存从<input> 传递的字符串的值(这个变量可能是问题的一部分)
6. 第二个变量是_output,它将保存要输出到 JavaScript 文件的值(我对这个变量没有任何问题)
7. 第三个变量是_DM 变量,它连接到我的DataManager 类(这是一个非常有问题)
在我的代码中发生的情况是,在 __construct 函数中声明 _DM 变量之后实际上没有发生任何事情。如果我用// 将_DM 变量的声明注释掉,那么之后的一切都有效。我检查了DataManager 类可以被FetchSchool 类找到,所以我不知道为什么会发生这个错误。
这是我的代码:
<?php
class FetchSchool {
public $_string; // string that will hold the value that is passed in
public $_output; // output string of HTML
public $_DM;
final public function __construct($_passed_string){
echo "<option>".$_passed_string."</option>";
$this->_string = ($_passed_string) ? $_passed_string : "";
$this->_output = "";
$this->_DM = ($_passed_string) ? new DataManager("localhost","root","root","hw_share") : NULL;
if ($this->_string){
echo "<option>works</option>";
} // end if
else {return "";}
} // end __construct
} // end class fetchSchool
if (@$_GET["str"]){
$_fetch_school = new FetchSchool(@$_GET["str"]);
} // end if
?>
"<option>".$_passed_string."</option>" 工作并自动显示用户键入的任何内容,但 "<option>works</option>" 不显示,尽管它应该显示。
【问题讨论】:
标签: javascript php ajax function class