鍍金池/ 問(wèn)答/HTML/ Vue,獲取API數(shù)據(jù)

Vue,獲取API數(shù)據(jù)

    mounted:function () {
        var newServer=JSON.stringify(this.toServer);
        $.ajax({
            url:'/Add',
            type:'post',
            data: newServer,
            dataType:'json',
            crossDomain: true,
            contentType : 'application/json',
            processData : false,
            success:function (rel) {
                console.log(rel);

            },
            error:function (rel) {
                console.log(rel);
            }
        })
    }
    
    為什么這個(gè)傳給data的newServer不加{}就會(huì)報(bào)500 (Internal Server Error)?
回答
編輯回答
默念

data里面直接傳this.toServer本身是支持json數(shù)據(jù)的,不需要轉(zhuǎn)字符串(而且你轉(zhuǎn)出來(lái)的字符串后臺(tái)只能通過(guò)特殊方式獲取)

2017年3月6日 14:28
編輯回答
萢萢糖

圖片描述

這是我打印出來(lái)的toServer

2017年11月14日 19:23
編輯回答
孤島

clipboard.png

2017年4月16日 09:24
編輯回答
寫(xiě)榮

ajax的data默認(rèn)會(huì)接收一個(gè)字符串,然后拼接在參數(shù)的后面,類(lèi)似這樣:url?a=1&b=2,如果想要傳一個(gè)json對(duì)象(即contentType:json),那么要加processData:true,

2017年2月20日 21:01
編輯回答
影魅

傳過(guò)去的數(shù)據(jù)不是標(biāo)準(zhǔn)的json吧你打出來(lái)看了嗎。500是服務(wù)器沒(méi)解出來(lái)你的參數(shù)。

2018年1月18日 16:17
編輯回答
乖乖瀦

想看下你的this.toServer打印出來(lái)是什么樣子的。

2017年11月11日 19:01
編輯回答
她愚我
2018年1月22日 22:58