vue中ajax请求

$.post("http://localhost:3000/go2",{money:that.money,time:that.time,
               name:that.name,num:that.num,zhi:that.zhi,city:that.city,xin:that.xin,shou:that.shou

               },function(data){
                  
                      that.msg = Number(data[0].money)+Number(that.money)
                      $.post("http://localhost:3000/go",{money:that.msg,time:that.time,
               name:that.name,num:that.num,shou:that.shou

                       },function(data){
                       //console.log(data)
                          if(data=="成功"){
                               alert("数据更新成功")
                                that.$router.push("/wodeqian")
                            }else{
                            alert("数据更新失败")
                           }
                   })
                     
            })


          }
            
       }
  } 
app.post("/go", function(req, res) {

    res.header("Access-Control-Allow-Origin","*")
    
// console.log(req.body)
// console.log(req.query)
 
 
    let money = req.body.money;
    let time = req.body.time;
    let name = req.body.name;
    let num = req.body.num;
    let zhi = req.body.zhi;
    let city = req.body.city;
    let xin = req.body.xin;
    let shou = req.body.shou;
     console.log("222222222222222222222222222222222222222222")
     console.log(shou)
    mongodb.connect(url1,function (err,database) {
                 database.collection("users",function(err,coll){
                      coll.find({PhoneNumber:shou}).toArray(function(err,data){
                          if(data.length>0){
                          	coll.updateOne({PhoneNumber:shou},{$set:{money:money,time:time,name:name,num:num}},function(){
                                  res.send("成功")
                                  database.close();
                              })
                                
                      }
                 })
            })
    
      })
    
 })   
//  mongodb.connect(url1,function (err,database) {
//               database.collection("user",function(err,coll){
//                    coll.find({name:name}).toArray(function(err,data){
//                        if(data.length>0){
//                              res.send("已存在")
//                              database.close();
//                        }else{
//                            coll.save({money:money,time:time,name:name,num:num,zhi:zhi,city:city,xin:xin,shou:shou},function(){
//                                res.send("成功")
//                                database.close();
//                            })
//                        }
//                    })
//               })
//          })
       



app.post("/go2", function(req, res) {

    res.header("Access-Control-Allow-Origin","*")
    
 console.log(req.body)
 console.log(req.query)
 
 
    let money = req.body.money;
    let time = req.body.time;
    let name = req.body.name;
    let num = req.body.num;
    let zhi = req.body.zhi;
    let city = req.body.city;
    let xin = req.body.xin;
    let shou = req.body.shou;
     
     //console.log("注册")
    mongodb.connect(url1,function (err,database) {
                 database.collection("users",function(err,coll){
                      coll.find({PhoneNumber:shou}).toArray(function(err,data){
                          if(data.length>0){
//                        	console.log("11111111111111111111111111111111111111")
//                        	console.log(data)
                          	res.send(data)
                          	
                          database.close()   
                      }
                 })
            })
    
      })
    
   })  

 

Vue是一种流行的JavaScript框架,用于构建用户界面。采用了组化的开发方式,使得前端发更加模块化和可维护。而Ajax是一种用于在后台与服务器进行异步信的技术,可以在不刷新整页面的情况下更新部分页面内容。 在VueAjax请求可以通过使用Vue的内置方法或者第三方库来实现。Vue内置了一个名为`axios`的库,它是一个基于Promise的HTTP客户端,可以用于发送Ajax请求。 以下是使用axios发送Ajax请求的基本步骤: 1. 首先,在你的项目安装axios库。可以使用npm或者yarn命令进行安装:`npm install axios`或者`yarn add axios`。 2. 在需要发送Ajax请求的组件,引入axios库:`import axios from 'axios'`。 3. 使用axios发送请求,可以通过调用axios的各种方法(如get、post等)来发送不同类型的请求。例如,发送一个GET请求可以使用`axios.get(url)`方法。 4. 处理请求的响应,axios返回的是一个Promise对象,你可以使用`.then()`方法来处理成功的响应,使用`.catch()`方法来处理错误的响应。 下面是一个简单的示例代码,演示了如何在Vue使用axios发送GET请求: ```javascript import axios from 'axios'; export default { methods: { fetchData() { axios.get('https://api.example.com/data') .then(response => { // 处理成功的响应 console.log(response.data); }) .catch(error => { // 处理错误的响应 console.error(error); }); } } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值