2017-12-16 4 views
2

Ich habe Daten in mysql i Umwandlung ist, dass als json URL codierte,Ist es möglich, JSON-Daten mit URL-Codierung zu bekommen?

ich AngularJS bin mit Daten zu holen dies ist mein unter AngularJS Code

Das ist mein Winkel Skript:

angular 
    .module('hameedApp', []) 
    .controller('hameedController', function($scope, $http) { 

     $http({ 
      method: 'GET', 
      url: 'json2.php' 
     }).then(function(response) { 
      $scope.contacts = response.data; 
     }).catch(function(response) { 
      console.log('error'); 
     }) 
    }); 

Das ist mein json2.php Code:

 <?php 
     $connect = mysqli_connect("localhost", "root", "", "recruiter"); 
     $sql = "SELECT * FROM recruiter"; 
     $result = mysqli_query($connect, $sql); 
     $json_array = array(); 
     while($row = mysqli_fetch_assoc($result)) 
     { 
      $json_array[] = $row; 
     } 
     echo print_r(json_encode($json_array)); 
     ?> 

Wenn ich json2.php in Postbote url treffen, erfolgreich i go t wie json Antwort,

Wenn ich {{contacts}} in meine HTML-Datei, erfolgreich habe ich JSON Antwort, aber wenn ich ng-repeat {{contact.somestuff}}, habe ich keine Daten erhalten. Irgendwelche Ideen ?

+1

Sie brauchen nicht 'print_r'. Was siehst du in '{{contacts}}'? Zeige uns auch die 'ng-repeat' – charlietfl

+0

hi @charlietfl ich bin hameed Freund, der auch in seinem Projekt arbeitet, in {{contacts}} er hat eine json Antwort –

+0

zum Beispiel: {{name: gleich, Alter: 20} } das zeigt in html korrekt –

Antwort

3

Lösung erhalten. Ich habe gerade print_r entfernt und es funktioniert!

 <?php 
     $connect = mysqli_connect("localhost", "root", "", "recruiter"); 
     $sql = "SELECT * FROM recruiter"; 
     $result = mysqli_query($connect, $sql); 
     $json_array = array(); 
     while($row = mysqli_fetch_assoc($result)) 
     { 
      $json_array[] = $row; 
     } 
     echo (json_encode($json_array));  
     ?> 
Verwandte Themen