415错误及解决方法

出现415错误的解决方法: 
1. 前端看ajax请求的contentType是否与后端一致 
2. 看发送的数据格式是否正确。

function getAddDirResponse(data) {
    $.ajax({
        url:'/algor/api/datadirs',
        type:'POST',
        contentType: 'application/json; charset=UTF-8',
        async:false,
        dataType:'json',
        data:JSON.stringify(data),
        success: function (response) {
            console.log(response);
        }
    })
}

重点:JSON.stringify()方法

猜你喜欢

转载自blog.csdn.net/CoderTnT/article/details/86303467