javascript - angular 向后台发送数据,出现2次请求
天蓬老师
天蓬老师 2017-04-11 12:37:46
[JavaScript讨论组]

因为要兼容IE7,没有用到route功能,在index.html页面include了菜单和登陆注册页面(header.html),在header页面中点击登陆时,后台接收到2次请求,一次无数据,第二次成功接收数据了。我检查页面了没有引用2次controller,但是不知为啥就是触发了2次请求。还请各位大神指点
html

登录注册

135123456789退出

购物车({{itemtotal}})

  • 时尚款BBBB手表{{item.name}}
    {{item.itemcount}}

    {{item.price * item.itemcount | number: 2}}
    删除

  • 共({{itemtotal}})件商品
    {{total| number:2}}

  • 手机号码:

    请输入11位手机号码

    请输入正确的手机号码

  • 密码:

    请输入密码

    2-20个字符,可由中文、字母和数字组成

注册新账号 忘记密码?

  • 手机号码:

    请输入11位手机号码

    请输入正确的手机号码

  • 验证码:

    请输入正确验证码

    2-20个字符,可由中文、字母和数字组成

  • 密码:

    请输入密码

    2-20个字符,可由中文、字母和数字组成

  • 确认密码:

    两次输入的密码必须一致

    两次输入的密码必须一致

  • 服务条款、隐私政策 请先同意协议

js代码:

function LoginCtrl($scope,$http,$rootScope) {
   // console.log("请求进入")
    // 二级导航显示
    $(".telWatch").on("mouseenter",function(){
        $(".secNav").slideDown(function(){
            $(".secNav").stop(true);
        })//.stop(true,true);
        return;
    })
    $(".telWatch").on("mouseleave",function(){
        $(".secNav").slideUp(function(){
            $(".secNav").stop(true,true);
        });
        return;
    })

    //登陆事件
    $scope.showLogin = function(){
        //页面层
        layer.open({
            type: 1,
            title:"登录",
            shadeClose: true,
            skin: 'layui-layer-rim', //加上边框
            area: ['500px', '500px'], //宽高
            content: $('.login')
        })
    }
    //注册事件
    $scope.showRegin = function(){
        //页面层
        layer.open({
            type: 1,
            title:"注册",
            shadeClose: true,
            skin: 'layui-layer-rim', //加上边框
            area: ['500px', '500px'], //宽高
            content:$('.reg')
        })
    }


    //注册
    $scope.addUsers = function (item) {
        //表单正常提交
        if($scope.userForm.$valid){
            if($scope.user.pwd != $scope.user.pwd2){
                $(".pwd2").show();
                return false
            }else{
                $(".pwd2").hide();
            }
            var url = "http://10.12.12.74:30030/gateway.do";
            //正常提交表单
            $http({
                method : 'POST',
                url : url,
                data: {phone:phone,password:pwd},
                header:headers
            }).success(function(data, status) {
                console.log(data.msg);
               // alert(item.pwd,item.pwd2)
               // $(".layui-layer-close1").click();
               // $('.user').show();
               // $(".loginItem").hide();
            }).error(function(data, status) {

            });

        }
        else{
            $scope.submitted = true;
        }
    };
    $scope.rebpwd = true;

    //登陆
    $scope.userlogin = function (phone,pwd) {
        console.log(phone);
        //表单正常提交
        if($scope.loginForm.$valid){
            //正常提交表单
            var url = "http://10.12.12.74:30030/gateway.do";
            var headers= {'Content-Type':'application/json'};
            $http({
                method : 'POST',
                url : url,
                data: {phone:phone,password:pwd},
                header:headers
            }).success(function(data, status) {
                console.log(data.msg);
            }).error(function(data, status) {
                console.log(data.msg);
            });
        }
        else{
            $scope.submitted = true;
        }
    };

    $scope.logout = function(){
        alert("退出按钮")
    }

}
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(2)
迷茫

你的userLogin请求跨域了,因此先需要一次HTTP OPTIONS请求,来判断对应server是否允许资源访问。

参见 http://stackoverflow.com/ques...

怪我咯

你的userLogin请求跨域了,因此先需要一次HTTP OPTIONS请求,来判断对应server是否允许资源访问。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号