【问题标题】:xml parse error no element found while using JSON?xml解析错误使用JSON时找不到元素?
【发布时间】: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?

标签: json ajax xml


【解决方案1】:

似乎有一个错字;我在手机上,所以我看不到行号,但是在你的 Ajax 调用的底部附近,你有“url:commentUri”;你是想说“commentUrl”吗?

编辑:没关系,我现在知道这是故意的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 2017-08-03
    • 2015-04-04
    相关资源
    最近更新 更多