0

I am new in phonegap app development. I want to create an app that will communicate (CRUD operations) with server. I have created a json using php. now I want to access that file using angularJS. But can't access that file ("http://apptest.byethost5.com/view.php") from server. But localhost gives me the correct result. I think there has some permission problem to that file. I have changed the file permission to 755 but that does not work. Can you please suggest the correct way to deal with this problem.

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
    <table>
        <tr ng-repeat="x in names">
            <td>{{ x.firstname }}</td>
            <td>{{ x.lastname }}</td>
        </tr>
    </table>
</div>

<script>
 var app = angular.module('myApp', []);
 app.controller('customersCtrl', function($scope, $http) {
 $http.get("http://apptest.byethost5.com/view.php")
     .then(function (response) {$scope.names = response.data.records;});
 });
</script>
</body>

1 Answer 1

1

If the page being requested is on a different server, then for security reasons that server must explicitly allow cross-origin requests

Add this to the top of view.php

header("Access-Control-Allow-Origin: *")
Sign up to request clarification or add additional context in comments.

1 Comment

If you don't want to allow requests from any domain, be sure to replace * in the above with your specific requesting domain.

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.