-1

Hello I am trying to fetch data of specific user using php and AngularJS but the AngularJS is not adding Params in my code I tried all the ways but nothing works for me, I dont know what wrong in it I am using HTTP.GET procedure

Here is my JS code

var app = angular.module('myApp', ['ui.bootstrap']);

app.filter('startFrom', function() {
    return function(input, start) {
        if(input) {
            start = +start; //parse to int
            return input.slice(start);
        }
        return [];
    }
});
app.controller('customersCrtl', function ($scope, $http, $timeout) {
    $http.get('pages/modVehiclePayments/getPendingPO.php', {
        params: {
            source: link,
            getvendornumber: user.phonenum
        }
     }).success(function(data){
        $scope.list = data;
        $scope.currentPage = 1; //current page
        $scope.entryLimit = 50; //max no of items to display in a page
        $scope.filteredItems = $scope.list.length; //Initially for no filter  
        $scope.totalItems = $scope.list.length;
    });
    $scope.setPage = function(pageNo) {
        $scope.currentPage = pageNo;
    };
    $scope.filter = function() {
        $timeout(function() { 
            $scope.filteredItems = $scope.filtered.length;
        }, 10);
    };
    $scope.sort_by = function(predicate) {
        $scope.predicate = predicate;
        $scope.reverse = !$scope.reverse;
    };
});

Here is my PHP

$VendorNum = $_GET['getvendornumber'];

$query="SELECT * FROM tblvendors WHERE VendorNo='$VendorNum' AND statuscode='2'";

$result = $conn->query($query) or die($conn->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $arr[] = $row;  
    }
}
# JSON-encode the response
$json_response = json_encode($arr);

// # Return the response
echo $json_response;
Rtra
  • 514
  • 12
  • 25

2 Answers2

1

First you have invoke the array data from select query like this.

Php:

$query = "SELECT * FROM tblvendors WHERE VendorNo='$VendorNum' AND statuscode='2'";    

and return the value as json format.

 return json_encode($query);

Angularjs

$http.get('pages/modVehiclePayments/getPendingPO.php').then(function (res) {
          $scope.data = res.data; 
});
console.log($scope.data) 
  • this is now what I am getting `SyntaxError: missing : after property id $http.get({'pages/modVehiclePayments/getPendingPO.php').success(function(res){` – Rtra Mar 01 '17 at 17:33
  • Actaully I am trying to select data using WHERE Clause and I want to load data using that its not sending the variable value using GET my url will be like this **pages/modVehiclePayments/getPendingPO.php?getvendornumber=VAC-11700000001** but its not working – Rtra Mar 01 '17 at 17:44
  • Stop using "success".here Use this: $http.get('path').then(function (res){ success msg },function (res){ error msg}); – Alagendran Ayyadurai Mar 01 '17 at 17:46
  • Perfect but the problem is now I am getting `
    Notice: Undefined index: getvendornumber in C:\xampp\htdocs\pakmotor\administration\pages \modVehiclePayments\getPendingPO.php on line 5
    []` No value of getvendornumber is sent how can i forward textbox value
    – Rtra Mar 01 '17 at 17:52
  • Go and check the error on getPendingPo.php in 5th line. Or show me the 5th line of coding. – Alagendran Ayyadurai Mar 01 '17 at 18:03
  • here is the fifth line: **$VendorNum = $_GET['getvendornumber'];** – Rtra Mar 01 '17 at 18:07
  • I noticed that `ng-model="user.phonenum"` is not getting any value but its value is undefined if I can load its value automatically it wont create problem – Rtra Mar 01 '17 at 18:11
  • In this case, you have to use $http.post and In php Remove $_GET into $_POST – Alagendran Ayyadurai Mar 01 '17 at 18:22
  • Use this link for your reference:https://www.w3schools.com/angular/angular_http.asp – Alagendran Ayyadurai Mar 01 '17 at 18:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136984/discussion-between-object-and-rtra). – Alagendran Ayyadurai Mar 01 '17 at 18:23
  • OK I am there on chat – Rtra Mar 01 '17 at 18:37
0

Actually I think your php return a "painText". Try to fetch your data with a JSON.parse or try to add a JSON header in your php.

 $scope.list = JSON.parse(data);
Steeve Pitis
  • 4,283
  • 1
  • 21
  • 24