不同来源的请求? [英] Different source from requests?

查看:163
本文介绍了不同来源的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务:

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]);
          });
        }
      }
    };

现在,当我执行code,我看到这在我的开发工具:

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

网络开发者工具

在哪里这是从哪里来的?在

Where does this come from? The

的console.log(请求);

console.log("request");

仅获取执行一次,但显然有2个请求?

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

推荐答案

在短,指数是你正在浏览的网页。

如果你打开​​一个网页页面而不指定index.html页面,则服务器将尝试加载索引文件的文件夹。当Chrome需要告知你的错误的console.log()的,它不能因为它不知道实际文件名。

因此,(指数)

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)

这篇关于不同来源的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆