Ajax Post Request收到错误,错误为“状态”:415,“ statusText”:“不支持的媒体类型”

时间:2019-03-28 13:26:02

标签: javascript jquery html ajax

我使用附件(任何文件)的ajax调用发送了发帖请求,但出现类似“不支持的媒体类型”状态码(415)的错误,

我的代码在下面。

<!DOCTYPE html>
<html>

<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


    <script type="text/javascript">
        $(document).ready(function () {
            $('#json').click(function () {
                alert('json');

            });

            $('#ajax').click(function () {

                var form1 = new FormData();
                form1.append("Test", "http://seekvectorlogo.com/wp-content/uploads/2018/02/opentext-vector-logo-small.png");

                $.ajax({
                    "async": true,
                    "crossDomain": true,
                    "url": RestApi,
                    "method": "POST",
                    "headers": {
                        "authorization": "Basic 12c3lzYWRtaW46cGFzc3dvcmQtMQ==",
                        "cache-control": "no-cache",
                        "postman-token": "2998576a-75d7-2f15-2f5a-84a8733df87a"
                    },
                    "processData": false,
                    //"contentType": false,
                    "contenttype": "multipart/form-data"`enter code here`,
                    "Content-Disposition": "form-data",
                    //"data": form1,
                    "data": JSON.stringify({
                        "file": "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"
                    }),

                    success: function (result) {
                        alert("File available at: ", result);
                    },
                    error: function (result) {
                        var obj = result;
                        console.log(obj);
                        alert(JSON.stringify(obj));
                    }
                });
            });
        });



    </script>
</head>

<body>

    <button id="ajax">ajax call</button>
    <button id="json">json</button>


</body>

</html>

响应应为如下所示的api:

  

API /附件/ 78b8b5a579bd427f90f657a147e44ccd

0 个答案:

没有答案