axios param的数据始终post不过去

    // Send a POST request
                axios({
                    method: 'post',
                    url: this.url + 'vdata/vdata_cate/createVdataCateProcess',
                    data: {
                     param:JSON.stringify(this.formValidate),//转为json字符串
                    },
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    },
                }).then((response) => {

                    //刷新taken 第10步
                    this.getNewToken();

                    if (response.data.r == "success") {
                        swal({
                            type: "success",
                            title: "成功!",
                            text: "添加成功",
                            confirmButtonText: "确认",
                            allowOutsideClick: true,
                            timer: 1300,
                        }, function() {
                            //取消窗口
                        });
                    } else {
                        console.log(response.data);
                        swal({
                            type: "error",
                            title: response.data,
                        });
                    }

                });

param的数据始终post不过去

阅读 2.6k
4 个回答

headers 中的 ContentType 和 Payload 冲突

经过 JSON.stringify 转换后是一个 JSON 字符串,但是 application/x-www-form-urlencoded 要求是使用key=value 的形式对参数进行包装,多个参数使用 & 拼接。

解决办法。

  • 1、 使用 QS 包中的 qs.stringify 处理对象。
  • 2、 去掉 JSON.stringifyContent-Type 修改为 application/json
  • 方法2 如果是在 PHP 将无法通过 $_POST 取值,需要使用 file_get_contents('php://input')。在一些框架中,需要使用 Request::getContent 方法

看下控制台有报错吗? 然后确认一下Network上的请求的参数没带上?

url会不会错了,或者没写端口;刷新token这样子你每次调用都得写,封装下axios然后在拦截器里面写会好很多

新手上路,请多包涵

你是不是搞混了,data里面不用再写param了,应该用下面这一行就行了
data: JSON.stringify(this.formValidate),//转为json字符串

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题