简体   繁体   中英

Get data from php to angularjs doesnt working

I'm new in Angular I want to get a SQL request from php script to angular, but I see only a big bulleted list and I dont know what is the problem.

My html code:

.
.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js">
</script>
<script src="../js/proc_list.js"></script>
.
.
.
<div align="center" id="prod_list" ng-controller="proc_list">

<ul>
    <li ng-repeat="processor in proc">
    {{processor.manufacturer}}
    <p>{{processor.description}}</p>
    {{processor.price}}
    </li>
</ul>   

</div>

Controller code:

function proc_list($scope, $http){
$http.post('../phps/get_proc_list.php').success(function(data){
        $scope.proc = data;
    });
}

PHP code:

$received_data = file_get_contents("php://input");

$objData = json_decode($received_data);

require_once('login.php');
.
.
//Connect to database and send query
.
.
 $data_requested = json_encode($data);

echo $data_requested;

I tried to do similar like this link: http://www.cleverweb.nl/javascript/a-simple-search-with-angularjs-and-php/

but its still not working. Anybody has any idea? Thank you

The correct syntax of $http.post is $http.post('/someUrl', data).success(successCallback);

Read more about in the AngularJS docs: http://docs.angularjs.org/api/ng.$http#post

好的,现在可以正常工作了,在这种情况下,无需编码以对json $ data进行编码,只需将其发送回去即可

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM