2016-11-16 9 views
2

私は、単純な自動補完jQueryのPHPのクラスと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 
?> 

答えて

0

__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(); 
+0

ありがとうございますが、それも動作していません。 –

+0

@SwapnilRanadiveデータを適切にエコーします。自動完了を確認してください。ありがとう、 –

+0

はい、パスが正しくありませんでした。ご協力いただきありがとうございます。 –