bekommen Wenn ich versuche, eine Liste mit Ajax ein Verfahren im Frühjahr Controller zu senden bekomme ich diesen Fehler:Ajax und Spring MVC kann nicht die Liste Feder Methode
Content type 'application/x-www-form-urlencoded' not supported
meinen AJAX-Code:
$('#btn-save').click(
ajaxSend();
);
function ajaxSend() {
$.ajax({
url: "/kepres2Web/mvc/spatiu/update",
type: 'POST',
dataType: 'json',
contentType: "application/json;charset=UTF-8",
data: JSON.stringify(rects),
success: function (data) {},
error: function (data, status, er) {},
headers: {
'Content-type': 'application/x-www-form-urlencoded'
}
});
}
meine Methode:
@RequestMapping(value = "/update", method = RequestMethod.POST, produces = {"application/json", "application/xml"}, consumes = {"application/x-www-form-urlencoded"})
public String update(@ModelAttribute("record") Spatiu spatiu,@RequestBody List<Desk> deskList) {
System.out.println(deskList.get(0).getFill());
dao.update(spatiu);
//return null;
return "redirect:view?ls&id=" + spatiu.getId();
}
und meine Taste:
<button id="btn-save" type="submit" form="frmDetails" formaction="update">
<img src="${pageContext.request.contextPath}/img/actions/save.png">
<br>Salvare
</button>
EDIT
Fand heraus, dass der Frühling nicht versteht application/x-www-form-urlencoded als RequestBody so nahm ich es und hinzugefügt @ResponseBody auf Verfahren. Jetzt gibt es eine leere Liste zurück.
Sie Einstellung der Inhalt zweimal geben - einmal in der 'contentType' Option und einmal in der' headers' Option, und Sie sind es zwei verschiedene Werte einstellen. – ADyson
Siehe auch https://StackOverflow.com/questions/33796218/content-type-application-x-www-form-urlencodedcharset-utf-8-not-supported- für eine mögliche Lösung für die Nachricht. – ADyson
Entfernte Header. Immer noch nicht arbeiten @ADyson. Derselbe Fehler –