zoukankan      html  css  js  c++  java
  • js vue 请求

    1. Vue 的 GET 请求
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    var vm = new Vue({ el: '#app', data: { resp: {}, api_url: '/index', }, methods: { get_data(){ this.$http.get(this.api_url) .then((response) => { // 用 set 将响应结果赋给变量 resp this.$set(this.resp,'data',response.body) }).catch(function(response){console.log(response)}) } } }) 2. Vue 的 POST 请求 var vm = new Vue({ el: '#app', data: { resp: {}, post_data: {'name':'abc'}, api_url: '/index', }, methods: { get_data(){ this.$http.post(this.api_url,this.post_data,{emulateJSON:true}) .then((response) => {this.$set(this.resp,'data',response.body)}) .catch(function(response){console.log(response)}) } } })  axios .post('https://www.runoob.com/try/ajax/json_demo.json',{id:id})

    .then(function (response) { console.log(response); }) .catch(function (error) { // 请求失败处理 console.log(error); });
    3. jQuery 的 GET 请求 $(function(){ $("#btn").click(function(){ $.ajax({ url:"/index", dataType:"json", data:{name:'abc'}, type:"get", success:function(resp){ var result result = JSON.parse(resp); } }) }) }) 4. jQuery 的 POST 请求 $("btn").click(function(){ $.post(url,{user:'abc',pwd:'******'},function(resp){ if(resp.success){ $.messager.alert("系统提示","添加成功","info"); }else{ $.messager.alert("系统提示","添加失败","error"); } },"json"); }
  • 相关阅读:
    《Thinking In C#》
    在图片上写字
    在设计期跟踪代码
    VS2003下的重构工具ReSharp
    监视剪贴板的变化
    一次重构导向设计模式的实践
    JENA学习的零散笔记
    jena处理Owl
    Maven库中.lastUpdated文件自动清除工具
    WEB数据挖掘(六)——Aperture数据抽取(2)
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/10657462.html
Copyright © 2011-2022 走看看