javascript - JSON.stringify 中未捕获的 InvalidStateError

标签 javascript jquery json stringify

我已经阅读了另一个线程,它并不好:Put data into JSON with Jquery

每当我尝试对对象数组进行 JSON.stringify 时,我都会收到一条错误消息:

Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable. 

这是我的 JS:

            var responseItems = [];

            var keynoteContainer = $('div.keynote-questions');
            var eventQuestionContainer = $('div.event-questions');
            var sessionContainer = $('div.session-questions');
            var eventId = $('#Evaluation-Event-Id').val();

            keynoteContainer.children().each(function (index, el) {
                var element = $(el);

                var id = "-1";
                var parentId = element.find('input[type=hidden]').val();
                var parentType = "Keynote";
                var responseValue = element.find('.response-item-slider').slider("option", "value");
                var responseText = "";

                var response = { "Id": id, "EventId": eventId, "ParentId": parentId, "ParentType": parentType, "ResponseValue": responseValue, "ResponseText": responseText };
                responseItems.push(response);
            });                    

            eventQuestionContainer.children().each(function (index, el) {
                var element = $(el);

                var id = "-1";
                var parentId = element.find('input[type=hidden]').val();
                var parentType = "EventQuestion";
                var responseValue = element.find('.response-item-slider').slider("option", "value");
                var responseText = element.find('textarea').val();

                var response = { "Id": id, "EventId": eventId, "ParentId": parentId, "ParentType": parentType, "ResponseValue": responseValue, "ResponseText": responseText };
                responseItems.push(response);
            });

            sessionContainer.children().each(function (index, el) {
                var element = $(el);

                var id = "-1";
                var parentId = element.find('input[type=hidden]').val();
                var parentType = "Session";
                var responseValue = element.find('.response-item-slider').slider("option", "value");
                var responseText = "";

                var response = { "Id": id, "EventId": eventId, "ParentId": parentId, "ParentType": parentType, "ResponseValue": responseValue, "ResponseText": responseText };
                responseItems.push(response);
            });

            responseItems = JSON.stringify(responseItems);

我尝试记录所有内容,但它只在我对其进行字符串化的最后一行中断。

我该如何解决这个问题?任何建议或信息将不胜感激。

最佳答案

我有同样的错误。就我而言,我在设置其中一个模型属性时忘记了 .val() 。在我尝试对模型进行 JSON.stringify 之前没有出现错误

        this.model.set(
        {
            customername: this.$("#customername").val(),
            jobtitle: this.$("#jobtitle"),  //This was the line causing the error
            testimonialtext: this.$("#testimonialtext").val()
        });

关于javascript - JSON.stringify 中未捕获的 InvalidStateError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18600962/

相关文章:

javascript - 从我的网站查询第三方网站的数据库

javascript - react : Are props objects passed automatically to children components or does there always exist some default props?

javascript - 使用 jQuery 清理代码注入(inject)

javascript - jquery-ui : drop&drag inventory with stackable items

php - 使用 jquery、ajax、php、mysql 关闭后永久隐藏信息框

javascript - Grails - 使用 JSON 通过 Ajax 从 Controller 渲染 map

javascript - 在rails app + jquery 中生成的链接错误地定向到本地主机

javascript - jQuery-ajax 'on click event' 不工作

javascript - Angular指令参数长度限制

javascript - 根据其多个属性从数组中删除元素