【发布时间】:2016-05-27 00:36:51
【问题描述】:
我正在使用 JSON 将数据放入我的数据库中,但是在使用 POST 时我得到了
XML Parsing Error: no element found Location: moz-nullprincipal:{7c3ebd98-a00f-4a72-8a89-8094946cef8e Line Number 1, Column 1:
浏览器得到正确的 JSON 文件,但我仍然得到错误:
function comment() {
if ($.trim($("textarea#inputdefault").val()) != "") {
var reacties = $("textarea#inputdefault").val();
var reactie = {
reactieId: 2,
Datum: "2016-05-25 01:20:54.843",
Inhoud: $("textarea#inputdefault").val(),
voorstelId: voorstelID
}
postAjaxCall(commentUri, reactie);
console.log("Input: " + reactie);
console.log("commentUri: " + commentUri);
console.log("voorstelID: " + voorstelID);
console.log("voorstelID: " + voorstelID);
$('textarea#inputdefault').val('')
} else {
alert("Vul iets in!");
}
}
function postAjaxCall(commentUri, comment) {
$.ajax({
type: 'POST',
url: commentUri,
data: JSON.stringify(comment),
contentType: 'application/json'
}).success(function (data) {
console.log("URL: " + commentUri);
console.log("data: " + JSON.stringify(comment));
})
}
我找不到我的错,而且已经浪费了几个小时
【问题讨论】:
-
是什么导致了这个错误?也许您正在调用的服务期望它是 XML 并忽略您的 contentType?