我正在使用此自动完成插件https://www.devbridge.com/sourcery/components/jquery-autocomplete/我正在使用下面的jQuery代码行$('#text-user').autocomplete({ serviceUrl: 'index.php?secController=studentProfile&action=employeeSearch', onSelect: function(suggestion) { alert('You selected: ' + suggestion.value + ', ' + suggestion.data); }});从php方面,它通过以下代码从数据库中获取建议publicfunction employeeSearch() { $arrayOfEmployee = array(); $arrayToPush = array(); $arrayToJSON = array(); $new_item = $this - > apicaller - > sendRequest(array( "controller" => "Employee", "action" => "employeeSearch", "searchCriteria" => $_REQUEST['searchCriteria'] )); $arrayOfEmployee = json_decode($new_item, true); foreach($arrayOfEmployee as $key => $employee) { $arrayToPush = array('value' => $employee['FullName'], 'data' => $employee['_id']['$oid']); array_push($arrayToJSON, $arrayToPush); } echo json_encode(["suggestions" => $arrayToJSON]);}格式正确,可以自动完成。现在的问题是,一直在获取所有数据。然后我意识到这可能是因为找不到文本框的searchCriteria而不是像调用一样在ajax中传递的。请帮我如何通过ajax像调用此插件一样为"searchCriteria" => $_REQUEST['searchCriteria']行传递searchCriteria?我试过像$('#text-user').autocomplete({ serviceUrl: 'index.php?secController=studentProfile&action=employeeSearch', type: 'POST', dataType: 'JSON', data: { searchCriteria: this.value }, .... ...它仍然获取所有员工,因为如果在数据库编码中将searchCriteria留空,它将获取所有员工请帮忙数据是{"suggestions":[{"data":"Aasiya Rashid Khan","value":"5aa662b0d2ccda095400022f"},{"data":"Sana Jeelani Khan","value":"5aa75d8fd2ccda0fa0006187"},{"data":"Asad Hussain Khan","value":"5aaa51ead2ccda0860002692"}..... 最佳答案 您正在发送POST请求(使用type: 'POST'),以便在服务器端的$_POST中找到您的变量,但是我在文档中没有看到POST,因此请使用默认的:客户端:$('#text-user').autocomplete({ serviceUrl: 'index.php?secController=studentProfile&action=employeeSearch', onSelect: function(suggestion) { alert('You selected: ' + suggestion.value + ', ' + suggestion.data); }});服务器端 :GET 09-19 20:05