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

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

原创
作者头像
用户6906169
修改2020-01-20 09:44:55
9600
修改2020-01-20 09:44:55
举报
文章被收录于专栏:用户6906169的专栏

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

代码语言:javascript
复制
//登录请求开始
                    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: '用户账号或密码不正确',
                                });
                            }
                        }
                    });

补充知识:

租用主机

按需购买:根据云主机内存大小,硬盘容量,服务器带宽、操作系统不同所售价格也不同 ①:腾讯云代金券2860礼包(希望对你有所帮助) ②:目前腾讯云3折秒杀活动,价格非常实惠。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

评论
作者已关闭评论
0 条评论
热度
最新
推荐阅读
目录
  • 补充知识:
    • 租用主机
    相关产品与服务
    云服务器
    云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档