前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >uniAPP跨域问题及接口传参数据项带双引号“”问题记录

uniAPP跨域问题及接口传参数据项带双引号“”问题记录

作者头像
ZhangXianSheng
发布2019-08-09 12:33:59
3.7K0
发布2019-08-09 12:33:59
举报

uniapp开发H5时,基本上都会遇到跨域问题:

下面是个完整的请求示例:

关键在于header请求头:

header: { 'Access-Control-Allow-Origin': '*', //跨域加上头 'Content-Type': 'application/x-www-form-urlencoded' },

Content-Type传入内容格式设置为'application/x-www-form-urlencoded'时

数据格式为"data":"66666"

与'Content-Type': 'application/json'

不同的是json格式不带“”--->data:6666,

发送内容格式的不同:数据格式也就不同;

具体内容类型参照:http://tool.oschina.net/commons

//登录请求开始
                    let loginurl = '/betago-api/auth/login';
                    let isok=false;
                    var that=this;
                    // console.log(datas);
                    uni.request({
                        url: loginurl, //登录API地址。
                        data: {
                            mobile: datas.account,
                            password: datas.password
                        },
                        method: 'POST',
                        dataType: "jsonp",
                        async: true,
                        header: {
                            'Access-Control-Allow-Origin': '*', //跨域加上头
                            'Content-Type': 'application/x-www-form-urlencoded'
                        },
                        //登录成功后返回
                        success: function(res) {
                            console.log(res.data);
                            //登录成功后存入缓存用户信息(必要信息)
                            let dataInfo=JSON.parse(res.data);
                            if (dataInfo.code=="0") {
                            
                            const userInfo1 = {
                                account: datas.account,
                                password: datas.password,
                                headImagePath: dataInfo.data.headImagePath,
                                coins: dataInfo.data.coins,
                                signature: dataInfo.data.signature,
                                userId: dataInfo.data.userId,
                                userTypeCode: dataInfo.data.userTypeCode,
                                testPlannedDate: dataInfo.data.testPlannedDate,
                                fileOssUpload: dataInfo.data.fileOssUpload,
                                LoginName: dataInfo.data.name,
                            };
                            service.addUser(userInfo1);
                            //返回登录成功信息
                            isok= true;
                                
                            } 
                            if (isok) {
                                that.toMain(datas.account);
                            } else {
                                uni.showToast({
                                    icon: 'none',
                                    title: '用户账号或密码不正确',
                                });
                            }
                        }
                    });
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档