angularJS ajax 调用后台提示跨域,但是访问的资源是在同一台服务器上

nginx 配置
server {

    listen       80;
    server_name 114.119.5.178  ;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /root/java/iBase4J-UI;
        index  index.html index.htm;
       if ( -f $request_filename){
    root /root/java/iBase4J-UI;
    break;
    }
    if ( !-e $request_uri){
     # proxy_pass http://114.119.5.178:8080;        
            rewrite ^ http://$server_name:8080/iBase4J-Web$request_uri? permanent;
    }
    }

}

angularJS代码
angular.module('app')

    .controller('loginController',[ '$rootScope', '$scope', '$http', '$state', function($rootScope, $scope, $http, $state) {
    $scope.user = {};
            $scope.login = function () {
                    $.ajax({
                            url : '/login',
                            data: $scope.user
                    }).then(function(result) {
                            if (result.httpCode == 200) {
                                    $state.go('main.sys.user.list');
                            } else {
                                    $scope.msg = result.msg;
                                    $rootScope.$apply();
                            }
                    });
            }

} ]);
截图
图片描述

nginx

图片描述

angualrJS

阅读 2.8k
1 个回答

你说是同一个服务器,但是是同一个域名吗?

假如 www.baidu.com 和 yun.baidu.com 都是指向 172.27.35.99的服务器,但是这是算跨域!

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题