0

I have successfully return JSON data using PHP and delivered to my user's browser successfully. The return JSON is like this.

{
 "html":"<div class='sampleClass'><span>Test Site</span></div>"
}

Here is my angular js code

    var app = angular.module('myApp', []);
    app.controller('testCtrl', function($scope, $http, $log) {
    var successCallBack = function(response){
            $scope.test=response.data.records;
    }
    var errorCallBack = function(response){
        $scope.error = response.data;
    }
    $scope.getAll = function(){
        $http.get("read_list.php").then(successCallBack,errorCallBack);

    }
});

And here is how I display the data

<tbody ng-init="getAll()">
    <tr ng-repeat="d in test">
        <td>{{ d.html }}</td>
    </tr>
</tbody>

What I want to achieve is to ouptut the above JSON like this

Test Site

just the Test Site only, not the whole html return.

I do some research about here but still I have no luck. I hope someone will help me with this.

BTW, I'm using angular js here to display the data.

Thanks.

Mary
  • 564
  • 3
  • 14
  • Why would you generate DOM elements through server side when you can do it inside your AngularJS code? – avilac Jan 02 '17 at 14:30
  • Is the above question not possible? – Mary Jan 02 '17 at 15:01
  • Please [edit] your question to clarify it. Is your JSON data, as shown, in your php program in your server, or has it been delivered to your user's browser already? – O. Jones Jan 02 '17 at 15:03
  • Well... you can add HTML code like this using PHP for example with an echo: 'echo "
    Test Site
    "', but I don't know if it's possible in any other way.
    – avilac Jan 02 '17 at 15:03
  • @O.Jones I have edited the question. I hope it is clear now. – Mary Jan 02 '17 at 15:23
  • Please add essential information to your question: **How** do you currently use the JSON from the response in your HTML document (show your Javascript code) ? – Daniel W. Jan 02 '17 at 15:48
  • @DanFromGermany I already add the javascript code in my question. Thanks – Mary Jan 02 '17 at 16:11
  • THis should help clear html. http://stackoverflow.com/questions/17289448/angularjs-to-output-plain-text-instead-of-html – flakerimi Jan 02 '17 at 17:15

0 Answers0