douyou7072 2015-01-17 13:58
浏览 135

XMLHttpRequest无法加载angularjs

I am learning from this site.

I use this for an Android application to fetch the PHP data and show the application.

When I start the web service in AngularJS, Google Chrome gives this error in the console:

XMLHttpRequest cannot load http://192.168.1.10/android_connect/JsonReturn.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

This is my JavaScript code:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script>function GetUsers($scope, $http) {
    // this is where the JSON from api.php is consumed
    $http.get('http://192.168.1.10/android_connect/JsonReturn.php').
        success(function(data) {
            // here the data from the api is assigned to a variable named users
            $scope.users = data;
        });
}</script>

Then I set the HTML code:

<div ng-controller="GetUsers">

<table>
<thead><tr><th>ID</th><th>Name</th><th>Email</th></tr></thead>
<tbody>
<tr ng-repeat="user in users"><td>{{user.id}}</td><td>{{ user.name }}</td><td>{{user.email}}</td></tr>
</tbody>
</tfoot></tfoot>
</table>

</div>

I tried all the possible solutions posted, but it doesn't seem to fix the issue in my code.

  • 写回答

2条回答 默认 最新

  • dongliu6848 2015-01-17 14:44
    关注

    You are trying to make a cross domain request using XMLHttpRequest. For that to work, the web server responding to the request needs to have the Access-Control-Allow-Origin response header set to *.

    评论

报告相同问题?

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导