使用$ http.get检索单个记录

I have a few functions in a PHP file that are to write and request data from a server database. The requests for these php functions come from a js file. My first function to write to the server works, but I am at a roadblock with no errors in my console to go on with for retrieving a single record.

Currently, I believe I have correctly pulled data, as I can see it in the console log, but the data does not seem to assign to the variables.

My PHP file

    switch($_GET['action']){
case 'writeInvoice':
        writeInvoice();
        break;
case 'fetchInvoice':
        fetchInvoice($_GET['num']);
        break;
}

function fetchInvoice($num){

$fqry = "SELECT customerName,
                dealerName,
                billTo,
                billStart,
                contractTerms,
                item,
                itemPrice,
                quantity,
                sharePercent,
                cost
                FROM invoice
                WHERE idInvoice = '{$num}'";


$qry = new Query($fqry,__LINE__,__FILE__);
$result = json_encode($qry->fetch_array());
print_r($result);


return $result;
}

My js/angular code

    $scope.editInvoice  = function($param){

    $http.get('DealerRec/writeInvoice.php?num='+$param+'&action=fetchInvoice', $scope.list)
        .success(function(data,status,headers,config){console.log("Data Taken"); console.log(data);
         fetchData = data; 
          $scope.list.idInvoice     = $param;
    $scope.list.customerName  = fetchData.customerName;
    $scope.list.dealerName    = fetchData.dealerName;
    $scope.list.billTo        = fetchData.billTo;
    $scope.list.billStart     = fetchData.billStart;
    $scope.list.item          = fetchData.item;
    $scope.list.price         = fetchData.price;
    $scope.list.qty           = fetchData.qty;
    $scope.list.contractTerms = fetchData.contractTerms;
    $scope.list.per           = fetchData.per;
    $scope.list.cost          = fetchData.cost;

 })
        .error(function(data,status,headers,config){ console.log("Data Not Taken"); });



    CustomModal.setOption(2);
};

My goal is to retrieve an Invoice from the database by invoice ID #, and store the field that I may be able to view and write over it.

My console is showing this, when I call the function on say, entry 12

Data Taken

(
    [num] => 12
    [action] => fetchInvoice
 )
                                          {"customerName":"SomeCustomer","dealerName":"SomeDealer","billTo":"Customer","billStart":"2015-06-10","contractTerms":"Billing Software    Terms","item":"SomeItem","itemPrice":"150.00","quantity":"20","sharePercent":"75","cost":"15.00"}

When the function executes, in its last line it opens a modal, where the data is set/editable.

The following part is wrong for sure:

fetchData = $http.get('DealerRec/writeInvoice.php?num='+$param+'&action=fetchInvoice', $scope.list)
    .success(function(data,status,headers,config){console.log("Data Taken"); console.log(data); })
    .error(function(data,status,headers,config){console.log("Data Not Taken"); });

You cannot assign the result(s) of $http service to fetchData like this. You need to do this in the success callback:

$http.get('DealerRec/writeInvoice.php?num='+$param+'&action=fetchInvoice',$scope.list)
    .success(function(data,status,headers,config){
        console.log("Data Taken"); 
        console.log(data); 
        fetchData = data; // this is what you have to do
    })
    .error(function(data,status,headers,config){ 
        console.log("Data Not Taken"); 
    });