Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用angularjs和JSON从数据库获取数据_Javascript_Php_Mysql_Angularjs_Json - Fatal编程技术网

Javascript 使用angularjs和JSON从数据库获取数据

Javascript 使用angularjs和JSON从数据库获取数据,javascript,php,mysql,angularjs,json,Javascript,Php,Mysql,Angularjs,Json,嗨,我试图用angularjs从数据库中获取数据,但它没有显示任何数据。我刚刚开始学习angularjs。有人能帮我吗?这是我的代码 income.html <div class="container jumbotron" ng-init= "getIncomeSource()" ng-controller="IncomeSourcesController" id="homejumbotron"> <table> <thead> &l

嗨,我试图用angularjs从数据库中获取数据,但它没有显示任何数据。我刚刚开始学习angularjs。有人能帮我吗?这是我的代码

income.html

<div class="container jumbotron"  ng-init= "getIncomeSource()" ng-controller="IncomeSourcesController" id="homejumbotron">
<table>
    <thead>
        <th>Name of the Employer</th>
        <th>Income From Salary</th>
        <th>TDS Deducted</th>
        <th></th>
    </thead>
    <tbody>
        <tr ng-repeat="x in incomesources" >

    <td>{{x.company_name}}</td>
    <td>{{x.user_income}}</td>
    <td>{{x.tax_deducted_salary}}</td>


    </tbody>
incomesources.php

function getIncomeSources()
{
session_start();
 $userInfo = $_SESSION['USER'];
 $userEmailid= $userInfo-> getEmailid();
 $res="SELECT *  FROM user_salary_details  WHERE email ='$userEmailid'";
 $result=mysql_query($res);            
 if ($row = mysql_fetch_assoc($result))
  {
     $companyname  = $row["company_name"];
     $userincome = $row["user_income"];
     $employetype   = $row["employe_type"];
     $tan     = $row["tan_employer"];
     $tax = $row["tax_deducted_salary"];
     $address = $row["address"];
     $state = $row["state"];
     $city=$row["city"];
     $pin=$row["pincode"];
     $data = array(
                    "success"   =>  "success",
                "companyname"   =>  $companyname,
                    "userincome"    =>  $userincome,
                "employetype"   =>  $employetype,
                "tan"   =>  $tan,
                    "tax"   =>  $tax,
                    "address"    =>      $address,
                    "state"   =>      $state,
                     "city" =>$city,
                     "pin"=>$pin,
              );

     echo json_encode($data);         
     }else{
        echo "No record exists for this user::";            
     }   
}

您的incomesources.php最初是否正常工作

select语句中的WHERE子句正在查找电子邮件=“$userEmailid”

我想您需要$userEmailid的内容。所以试着改变一下

$res="SELECT *  FROM user_salary_details  WHERE email ='". $userEmailid ."'";
编辑 由于您的php文件正在工作,并且您在上面的注释中提到,您可以在控制台中看到返回值,所以让我们看看您的html和js代码

在您的html中,请更改为

<tr ng-repeat="x in user" >

    <td>{{x.companyname}}</td>
    <td>{{x.userincome}}</td>
    <td>{{x.tax}}</td>

希望获得此帮助

这里您需要在success中再添加一个参数数据,我需要添加哪个参数。success(函数(状态、标题、数据){console.log(“响应数据:+JSON.stringify(数据));console.log(“响应数据:+JSON.stringify(数据))这里您使用了数据,但数据没有在任何地方定义。很抱歉,我认为php返回的是一个数组。它只是一个json对象。您可以将行更改为$scope.user={};
<tr ng-repeat="x in user" >

    <td>{{x.companyname}}</td>
    <td>{{x.userincome}}</td>
    <td>{{x.tax}}</td>
console.log("inside homecontroller:::");   

$scope.user = []; // this

$scope.getIncomeSource = function(){

console.log("Inside getPersonalInfo::::::");    
$http({