1

I am using the following code to do a http request.

<!DOCTYPE html>
<html>

<head>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <!--head_end-->
</head>

<body>

  <div class="company_profile" ng-app="company_profile" ng-controller="company_profileCtrl">
    <h2>&company_name</h2>
    <p><a href="&company_link" target="_blank" rel="nofollow">&company_link_text</a>
    </p>
    <p>{{companyProfile}}</p>
  </div>

  <!-- populate company_profile -->
  <script>
    var app = angular.module('company_profile', []);
    app.controller('company_profileCtrl', function($scope, $http) {
      $http.get("single-site.php").then(function(response) {
        $scope.companyProfile = response.data;
      });
    });
  </script>
</body>

</html>

However the code returns the source code of the html document it is in.

the single-site.php file exists and returns json data.

Thanks for your help

Edit I saw three other questions of people who had this problem, but none of them was correctly resolved.

11
  • 1
    you are missing the $http.get('/'), in call. And are you sure about your URL ? We do map the REST API link in it, not the page name. Commented Jun 17, 2016 at 6:25
  • try to do a console.log(response.data) and probably this can help you link Commented Jun 17, 2016 at 6:27
  • @Aravid, can you elaborate on the missing $http.get('/')? I don't really understand Commented Jun 17, 2016 at 6:33
  • 1
    Have you put something like that in your php file customer.php ? Commented Jun 17, 2016 at 6:36
  • 1
    probably you need only $scope.companyProfile = response.data.companyProfile but with angularjs and pretty url, you must be carefully Commented Jun 17, 2016 at 6:57

2 Answers 2

1

you are missing the $http.get('/'), in call. And are you sure about your URL ? We do map the REST API link in it, not the page name.

Like the below code.

$http({
  method: 'GET',
  url: '/someUrl'
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

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

Comments

0

In the url field you just have to write the full path. For example https://sitename/index.php/RandomController/yourfunction/
For me it worked! P.S. I use codeigniter

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.