美文网首页
【基础】发送请求

【基础】发送请求

作者: JerichoPH | 来源:发表于2017-10-12 21:56 被阅读12次

发送请求

  • get

    • html
    <button @click="getRequest()">ajax(get)</button>
    
    • js
    // get请求
    getRequest: function () {
        this.$http.get('get.php').then(function (res) {
            alert(res.bodyText); // 打印字符串结果
            console.log(res.body); // 打印结果
        }, function (err) {
            console.log(err.body);
        });
    }
    
  • post

    • html
    <button @click="postRequest()">ajax(post)</button>
    
    • js
    // post请求
    postRequest: function () {
        this.$http.post('post.php', {
            a: 1,
            b: 20
        }, {
            emulateJSON: true
        }).then(function (res) {
            alert(res.bodyText);
            console.log(res.body);
        }, function (err) {
            console.log(err.body);
        });
    }
    
  • jsonp

    • html
    <button @click="jsonpRequest()">ajax(jsonp)</button>
    
    • js
    // jsonp跨域请求
    jsonpRequest: function () {
        this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su', {
            params: {
                wd: 'a'
            },
            jsonp: 'cb'
        }).then(function (res) {
            console.log(res)
        }, function (err) {
            console.log(err)
        })
    }
    

相关文章

  • 【基础】发送请求

    发送请求 gethtml ajax(get) js// get请求getRequest: function () ...

  • Requests

    Requests库 目录一、Requests基础二、发送请求与接收响应(基本GET请求)三、发送请求与接收响应(基...

  • 使用requests发送请求-01

    发送get请求 发送post请求 上传文件 携带cookie发送请求 使用session发送请求

  • Retrofit基本使用

    Retrofit基本使用 内容 基础 接口配置 发送请求异步请求 && 示例一Convert && 示例二RxJa...

  • 自定义simple-http的使用

    最近自己写了一个发送http请求的组件,整个发送请求的实现是用的Okhttp,只是基于Okhttp基础上做了再次封...

  • 使用Apache的HttpClient发送Http请求

    使用Apache的HttpClient发送Http请求 1 基础概念 1.1 HttpClient、TCP/IP、...

  • iOS随笔

    基础...objc 客户端:clien 服务器:server 请求:客户端向服务器发送请求 响应:返回数据,对请求...

  • iOS网络NSURLConnection和NSURLSessio

    HTTP通信过程 NSURLConnection发送网络请求 block 方式 发送同步请求发送同步请求 发送异步...

  • 获取请求的参数

    发送请求----发送带参数的请求----获取请求参数 如何发送请求 发送请求格式:域名/模块/控制器/方法名模块是...

  • <Ajax>总结:知识点

    一、Ajax的基础: 1、使用步骤 1.1、步骤: 创建一个异步对象 设置请求方式和请求地址 发送请求 监听状态的...

网友评论

      本文标题:【基础】发送请求

      本文链接:https://www.haomeiwen.com/subject/ksfayxtx.html