0
我試圖發送一個JavaScript字符串數組(arrayItems
)到PHP Web服務,以便將查詢發送到MySQL數據庫。儘管如此,沒有數據從Web服務返回。當JavaScript String Array只有一個項目時,只能從Web服務正確返回數據。發送的JavaScript字符串數組,PHP Web服務
Web服務是PHP 30年6月5日。
樣本HTML來顯示返回的數據:
<ul>
<li ng-repeat="item in arrayInfo track by $index">ID: {{ item.idFruit }},
name: {{ item.name_fruit }}</li>
</ul>
的Ctrl
控制器的樣品:
angular.module('myApp').controller('Ctrl', ['$scope', 'services', Ctrl]);
function Ctrl($scope, services) {
var arrayItems = ["apple", "banana", "orange"];
services.getInfo(arrayItems).then(function(data){
$scope.arrayInfo = data.data;
});
};
的app.js的樣本來發送請求到Web服務:
.factory('services', ['$http', function($http){
var serviceBase = 'services/';
var obj = {};
obj.getInfo = function (arrayItems) {
return $http.get(serviceBase + 'get_info?arrayItems=' + arrayItems);
};
// return obj
return obj;
}]);
樣品在PHP Web服務:
private function get_info(){
if($this->get_request_method() != "GET"){
$this->response('', 406);
}
$arrayItems = (array)$this->_request['arrayItems'];
$fruits = implode("','", $arrayItems);
$query = "SELECT idFruit, name_fruit FROM Table_Fruits WHERE name_fruit IN
('$fruits')";
$r = $this->mysqli->query($query) or die($this->mysqli->error.__LINE__);
if($r->num_rows > 0){
$result = array();
while($row = $r->fetch_assoc()){
$result[] = $row;
}
$this->response($this->json($result), 200); // send user details
}
$this->response('', 204); // send user detail
}
謝謝*