2016-11-16 38 views
2

我有簡單的自動完成的JQueryPHP類和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

謝謝。是的,路徑不正確,感謝你的幫助。 –