Home > Web Front-end > uni-app > What should I do if uniapp fails to send a post request?

What should I do if uniapp fails to send a post request?

coldplay.xixi
Release: 2020-12-15 16:15:37
Original
4970 people have browsed it

The solution to the failure of uniapp to send a post request: First introduce jQuery in the Vue file, the code is [import jQuery from "@../../common/js/jquery-3.4.1.min.j ]; Then use jQuery to initiate an Ajax request.

What should I do if uniapp fails to send a post request?

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, this method is suitable for all brands of computers.

Recommended (free): uni-app development tutorial

Solution to the failure of uniapp to send a post request Method:

Regarding the cross-domain issue in uni-app, some people use browser plug-ins to lift the chrome browser CORS restrictions, some people modify manifest.json to achieve cross-domain purposes, and some people use it Intermediate plug-ins are used to complete it. But no matter which method is used, I hope everyone will always remember that everything remains the same. All operations are a collection of basic requests and data operations. Therefore, this note uses uni-app and jquery. Mixed use.

1. First introduce jQuery into the Vue file.

import jQuery from "@../../common/js/jquery-3.4.1.min.js";
Copy after login

2. jQuery initiates an Ajax request.

//请求接口数据
                var postData = {"account":mobile,"password":passwd};
                jQuery.ajax({
                    url:this.apiUrl+'index/login',
                    type:"post",
                    dataType:"json",
                    data:postData,
                    success:function(data){
                        if(data.code == 0){
                            uni.hideLoading();
                            uni.showToast({
                                title:"登陆成功",
                                icon:"none"
                            })
                            //将用户数据写入本地并执行跳转
                            uni.setStorage({
                                key:'user_info',
                                data:data.data,
                            })
                            uni.navigateTo({
                                url:'../index/index'
                            })
                        }else{
                            uni.showToast({
                                title:data.msg,
                                icon:none
                            })
                        }
                    },
                    error:function(){
                        uni.showToast({
                            title:"请求异常",
                            icon:none
                        })
                    }
                })
Copy after login

After testing, the local browser request was successful.

Related free learning recommendations: php programming (video)

The above is the detailed content of What should I do if uniapp fails to send a post request?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template