1

I am working on a project where i have to read the product and display it on my HTML page here is my Controller

  app.controller('SecondCtrl', function($scope,srvShareCart ,srvShareData,srvAddtoCart,$http) {
      $scope.product=[];
    $scope.One=function(){
     //alert($scope.ids);
       $scope.ids= srvAddtoCart.getData();
       for (var i=0; i<$scope.ids.length; i++){
      $http.get("http://www.ilexsquare.com/JwelTech/wordpress/api.php?function=GetProduct&id="+$scope.ids[i])
        .then(function (response) {

            srvShareCart.addData(response.data);
        });

        $scope.cart = srvShareCart.getData();
        console.log($scope.cart);

     }

    }

and here is My HTML page

<div ng-controller="SecondCtrl">
    <ul> <li class=oxy-list__item  ng-repeat="d in cart">{{d.title}}</li></ul></div>

here is a working API

this the Example API link

it's giving me an error in response.data which is coming as undefined.what is the issue in it ? I am getting the output but it's not in a form of array.. how do i Add those products in array. i have tried $scope.carts.push($scope.products); but its not storing as an array

8
  • Have you debugged response? What is returned in response? Commented Jan 24, 2016 at 12:35
  • Error: JSON.parse: unexpected character at line 1 column 1 of the JSON data this is the error Commented Jan 24, 2016 at 12:35
  • Ok, what is in $scope.ids[i] and what did you get returned if you call http://www.ilexsquare.com/JwelTech/wordpress/api.php?function=GetProduct&id="+$scope.ids[i] directly in your browser replaced by the id which was in $scope.ids[i]. Commented Jan 24, 2016 at 12:37
  • this the Example API link Commented Jan 24, 2016 at 12:38
  • This works for me. But are you sure, that you have the correct id within $scope.ids[i]. I mean have you checked this? Commented Jan 24, 2016 at 12:39

2 Answers 2

2

The response content type sent from the API is plain text instead of application/json

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

2

Try like this.

         $http.get({
            url: "http://www.ilexsquare.com/JwelTech/wordpress/api.php?function=GetProduct&id="+$scope.ids[i],
            dataType: "json",
            success: function (response) {
                srvShareCart.addData(response.data);
            },
            error: function (msg) {
                alert(msg.d);
            }
        });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.