Different source from requests?

微笑、不失礼 提交于 2019-12-11 11:59:13

问题


I have a service:

angular.module('services', [

])
    .service('userService', function ($http, $q, auth, userFactory) {
        var user = null;

        if(!user){

            userFactory.getUser2(auth.currentUser()).getValue(function(result){
                //console.log(result);
                user = result;
                console.log("request");
            });
        }

        this.getUser = function() {
            //console.log(user);
            return user;
        }

    })
;

This service calls a factory function:

userFactory.getUser2 = function(usr){
      return{
        getValue: function(callback){
          $http({
            method: 'POST',
            url:'http://groep6api.herokuapp.com/user',
            headers: {'Content-Type': 'application/x-www-form-urlencoded'
            //'authentication': 'bearer' + $window.localStorage.getItem('eva-token')
            },
            transformRequest: function(obj) {
              var str = [];
              for(var p in obj)
                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
              return str.join("&");
            },
            data : {username: usr}
          }).success(function (result) {
            //console.log("userfactory getUser:", result[0]);
            callback(result[0]);
          });
        }
      }
    };

Now when I execute the code, I see this in my developer tools:

Where does this come from? The

console.log("request");

Gets only executed one time, but apparently there are 2 requests?


回答1:


In short, index is the page you're on.
If you open a page page without specifying an index.html page then the server will try to load an index document for that folder. When Chrome needs to inform you of an error or console.log(), it can not since it does not know the actual file name.
Hence (index)



来源:https://stackoverflow.com/questions/34009157/different-source-from-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!