简体   繁体   English

向服务器发出AJAX请求时出现错误代码415

[英]Error code 415 while making AJAX request to server

I am sending an Ajax request to an endpoint on my server: 我正在向服务器上的端点发送Ajax请求:

Nothing bookSoldOut(boolean sold,
                    List<Long> books)
                        throws ErrorResponseException

... Where I am expecting the parameters: sold and books ...我期望的参数: soldbooks

In my ExtJS controller I am making a call in a function as follows: 在我的ExtJS控制器中,我正在如下函数中进行调用:

Ext.Ajax.request({
    url: '/book/price/bookSoldOut',
    method: 'POST',
    params: {
        'sold': true,
        'books': books,          
    },
    success: function(responseObject) {

    }
});

But I am getting an error code 415 - what I'm doing wrong? 但是我得到的错误代码是415-我做错了什么?

If books is a composite-type (array/object etc.) then it's highly likely that you need to serialise the data in some way or else as a result of the object's toString being invoked, [object object] will be what is actually being sent to the server. 如果books是复合类型(数组/对象等),则很有可能需要以某种方式对数据进行序列化,否则由于对象的toString被调用, [object object]实际上就是发送到服务器。 Typically you might use JSON encoded data in this case: 通常,在这种情况下,您可能会使用JSON编码的数据:

Ext.Ajax.request({
    url: '/book/price/bookSoldOut',
    method: 'POST',
    params: {
        sold: true,
        books: Ext.encode( books )  // <-- serialise (as string)
                                    // note that some browsers will trip up
                                    // over the trailing comma you had here
    },
    success: function(responseObject) {

    }
});

If there is still an error after this change then something is miss-configured on the server side. 如果此更改后仍然存在错误,则服务器端配置错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM