zoukankan      html  css  js  c++  java
  • vue this.$http.get post 跨域问题

    Get请求:

    Vue.http.get('http://localhost:9090/card-add',{
    params:{id:1,name:'aaa'}....->get请求必须加params
    })
    .then(
    (response)=>{
    //-响应成功回调
    console.log(response.data)
    },
    (response)=>{
    //-响应错误回调
    });
    浏览器正确情况:

    this.$http.get(this.url.getInfoURL?idNumber:idnumber,{
    emulateJSON: true
    }).then(res => {
    console.log("res={}",res);
    if (res.code === 0) {
    let dataObj = res.data;

    this.swCode = dataObj.swCode;

    this.regName = dataObj.regName;
    } else {
    this.descText = '获取失败,请稍后重试'
    }
    }).catch(err => {
    return this.$api.msg("服务器被外星人抓走了,请稍后重试")
    });

    Post请求:

    Vue.http.post('http://localhost:9090/st-add',{
    stName:"jxh",//st.stName,
    idCard:st.idCard,
    sex:st.sex,
    school:st.school,
    depict:st.depict,
    birthday:'2019/11/11',//st.birthday,
    clubs:st.clubs
    },{
    emulateJSON: true -->这一段必须存在!
    })
    .then(
    (response)=>{
    //-响应成功回调
    console.log(response.data)
    },
    (response)=>{
    //-响应错误回调
    });

    post错误情况,浏览器状况:

    这种错误情况,请和上面比对,你虽然能看到全部的请求参数,但结果就是404.

  • 相关阅读:
    4408: [Fjoi 2016]神秘数
    UOJ #35. 后缀排序[后缀数组详细整理]
    POJ 2887 Big String
    搜索过滤grep(win下为findstr)
    解决putty自动断开的问题
    > >> 将错误输出到文件
    环境变量
    端口被占用,查看并杀死占用端口的进程
    查找文件路径find
    【vim使用】
  • 原文地址:https://www.cnblogs.com/lykbk/p/dsfdsfdffer5ret454545.html
Copyright © 2011-2022 走看看