用ajax提交到后台,在与后台进行数据传输时报了Unsupported media type-415错误,查了后发现Content-Type未设置,contentType 的默认是application/x-www-form-urlencoded.后端对此设置的为application/json,so设置上就可以了,可参考如下代码:
$.ajax({ type:
'POST', url: url, dataType:
'json', contentType:
"application/json", data: JSON.stringify(setData), success:
function(data){ alert('数据加载成功'); }, error:
function(xhr, type){ alert('数据加载失败'); }});
本文介绍了解决使用Ajax向后台发送数据时遇到UnsupportedMediaType-415错误的方法。该错误通常是因为Content-Type设置不正确导致。文章提供了一个示例代码,展示了如何将Content-Type设置为application/json,并使用JSON.stringify()对发送的数据进行序列化。

484

被折叠的 条评论
为什么被折叠?



