I am writing a script using jQuery for loading some content into my page. At runtime nothing happens. I get this error when inspecting Firebug console:

TypeError: cyclic object value  
data: JSON.stringify({ columnName: _columnName })

Here is the code (placed inside <Head>):

<Script>
function changeContent(_columnName) {
        $.ajax({
            type: 'POST',
            url: '@Url.Action("GetContent")',
            data: JSON.stringify({ columnName: _columnName }),
            dataType: 'json',
            contentType: "application/json; charset=utf-8"
        }).done(function (resp) {
            CKEDITOR.instances.text.setData(resp.Text);
        }).fail(function () {
            alert("Error");
        });
    }
    $(function () {
        $("#side-content").bind('click', { a: "side" }, changeContent);
    });
</Script>

I used the tip here: Detecting and fixing circular references in JavaScript but could not find any circular relations!!!

Any point on saving my life would be so greatly appreciated.
- Kamran

有帮助吗?

解决方案

Problem solved and well understood

The main part of the problem was I did not know that the argument of the handler is DOM event. I thought that _columnName will receive event data which was wrong. It is DOM event in fact.

The working code follows:

<script>
    function changeContent(event) {
        $.ajax({
            type: 'POST',
            url: '@Url.Action("GetHomeColumnContent")',
            data: JSON.stringify({ columnName: event.data.a }),
            dataType: 'json',
            contentType: "application/json; charset=utf-8"
        }).done(function (resp) {
            CKEDITOR.instances.text.setData(resp.Text);
        }).fail(function () {
            alert("Error");
        });
    }
    $(function () {
        $("#side-content").bind('click', { a: 'side' }, changeContent);
    });
</script>

And about the cyclic value: DOM elements are cyclic in nature because every DOM element has a reference to its parent, and in turn every parent has references to its children, so a cyclic structure.

Thanks to all friends for their times: @Dogbert, @nnnnnn, @AD7six, @Xotic750 ;-)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top