繁体   English   中英

如何清除angular js中的404错误?

[英]how to remove 404 error in angular js?

.factory('ChartService', ['$http','$q',
        function ChartService($http,$q) {
            // interface

            // implementation
            var canceler = $q.defer();

            function getTableData() {

                return  $http.post('http://202.429.115.52:9906/oo/api.php?request=getSubfunctionWiseHCAndSW').success(function (data) {
                    if (data.mm == "No Data Available"){
                        localData();
                    }
                    return data;


                }).error(function(error){
                    alert("error")
                   canceler.resolve();
                    localData()
                  //  console.log(error)
                });



                }

            function localData(){
                        alert("loaddata")
               return  $http.get('vro/hcswc.json').success(function(response){
                    console.log(response+"==");
                    return response;
                }).error(function(error){
                    console.log(error);
                });
            }




            return {
                getTableData:getTableData
            }
        }
    ]);

错误 XMLHttpRequest无法加载http://192.127.215.52:9906/api.php?request=getSubfunctionrection 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问源' http:// localhost:63342 '。 响应的HTTP状态码为404。

App.js //解析代码

.state('app.vro', {
        url: "/vro/:isfirstActiveState",
        views: {
          'menuContent': {
            controller: "vrobCtrl",
            templateUrl: 'vrob/vrob.html'


            }
        }  ,
          resolve: {
              tableData:function(ChartService){

                  return ChartService.getTableData();
              }



          }
      })

您好我正在尝试获取数据表单服务。调用webservice时有一个条件。条件是如果我将收到错误,则从本地获取请求,换句话说,如果我从服务器收到任何错误而不是需要从中读取json文件本地的。 我需要使用resolve并调用我的服务,并在控制器上使用该数据。我的localData不返回要解决的数据。我的代码中的问题是什么..

这是一个示例http://plnkr.co/edit/0y9V0m2hmsUBRXoeyjig?p=preview我得到了错误纠正,但是它应该从本地json加载数据。为什么它不从本地json加载数据

使用$q管理$http请求是一种反模式,但是在这种情况下,我不知道另一种方法:

function getTableData() {

  var deferred = $q.defer();

  $http.post('http://202.129.215.52:9906/mondelez/api.php?request=getSubfunctionWiseHCAndSW')
    .then(
      // resolve callback
      function(data) {
        deferred.resolve(data.data)
        return data.data;
      },
      // reject callback make different request
      function(err) {
        $http.get('data.json').success(function(response) {
          deferred.resolve(response);              
        }).error(function(error) {
          deferred.reject()
        });

      })

  return deferred.promise;

}

DEMO

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM