我有简单的自动完成 JQuery
$(document).ready(function() {
$( ".autocomplete" ).each(function() {
$(this).autocomplete({
source: '/php/LiveSearch2.php?name='+ $(this).attr('name') + '&',
minLength: 1,
appendTo: "#container"
});
});
});
我已经编写了 php 类来推送值,但它不起作用。我在某个地方犯了一些错误。下面是LiveSearch2.php
<?php
class swapnil {
private $testname;
public $json;
public function __construct {
$this->testname = array('swapnil','ranadive');
$this->json = json_encode($this->testname);
echo $this->json;
}
}
$Business = new swapnil();
?>
当我使用没有类的 php 代码时,它工作正常。
<?php
$testname = array('swapnil', 'ranadive');
$json = json_encode($testname);
echo $json
?>
最佳答案
__construct
之后缺少括号。这里试试这个:
class swapnil {
private $testname;
public $json;
public function __construct() {
$this->testname = array('swapnil','ranadive');
$this->json = json_encode($this->testname);
echo $this->json;
}
}
$Business = new swapnil();
关于php 类和 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40624660/