使用Python、Ajax调用和Javascrip从MongoDB填充字段到HTML时收到JSON错误

2024-10-02 18:23:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Python从MongoDB数据库中检索数据,然后使用Ajax将数据发送到Javascript,然后使用数据填充页面HTML中的字段。当在本地机器上运行应用程序时,它会正常工作,但是当在Ubuntu服务器上运行应用程序时,我会遇到以下错误:

VM1419:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse ()

这是产生错误的Javascript函数:

function restoreData(){

$.get("restore_tab", function (tab_data) {
    var parsed = JSON.parse(tab_data);

    for (var i=0; i<parsed.length; i++){
        var tab_does_exist = document.getElementById(parsed[i].tab_number);
        if(tab_does_exist.innerHTML !== parsed[i].tab_name){
            createTab(parsed[i].tab_number, parsed[i].tab_name);
        }
    }
});

$.get("sender", function (data) {
    var parsed = JSON.parse(data);
    var tabs = document.getElementsByClassName("tab");

    for (i = 1; i < tabs.length; i++) {
        var clear = tabs[i].innerHTML = "";
    }

    for (i = 0; i < parsed.length; i++) {
        var delete_title = parsed[i].title;
        var restore = document.getElementById(parsed[i].tab);
        console.log(parsed[i].tab);

        restore.insertAdjacentHTML('beforeend', `
<div id='close_container_${parsed[i].article_id}'>
    <div class='close_border' id='close_border_${parsed[i].article_id}'>
        <div class='close_bar' id='close_bar_${parsed[i].article_id}'>
            <div class='close_btn' id='close_${parsed[i].article_id}' onclick='remove(id)'>×</div>
            <div id='full_article_${parsed[i].article_id}'>
                <h1 id='article_title_${parsed[i].article_id}'>${parsed[i].title}</h1>
                <div class='tooltip'>
                    <button type='button' onclick='saveArticle(event, id)' id='save_article_${parsed[i].article_id}'class='button ripple'>Update</button>
                    <textarea cols='120' rows='3' onclick='copy('article_reference_${parsed[i].article_id}'); copiedText('copied_${parsed[i].article_id}')' readonly type='text' id='article_reference_${parsed[i].article_id}' class='ref'>${parsed[i].reference}</textarea>
                    <span id='copied_${parsed[i].article_id}' class='tooltip_text'>click to copy &#x2398</span>
                </div>             
                <div onclick='speedRead(id)' class='speed_read' id='speed_read_${parsed[i].article_id}'>Click to SpeedRead</div>
                <p class='article_text' id='article_text_${parsed[i].article_id}'>${parsed[i].body}</p>
                <a id='article_url_${parsed[i].article_id}' target='_blank' href= ${parsed[i].url}>Click to open full article</a>
                <p style='color:#546de5;font-weight:900'>Your notes: </p>
                <textarea id='article_notes_${parsed[i].article_id}' placeholder='type article notes here'>${parsed[i].notes}</textarea>
            </div>
        </div>
    </div>
</div>`)
    }
});}

在开发人员控制台上,这是导致错误的数据库正在检索的内容:

[{"tab": "tab_2", "article_id": "746169745", "url": "http://dx.doi.org/10.1186/s12870-019-1847-2&quot;, "reference": "Reference: (2019-05-30). Transcriptional regulation of MdPIN3 and MdPIN10 by MdFLP during apple self-rooted stock adventitious root gravitropism, Available at: http://dx.doi.org/10.1186/s12870-019-1847-2 Last Accessed: [03-06-19]", "notes": "", "title": "Transcriptional regulation of MdPIN3 and MdPIN10 by MdFLP during apple self-rooted stock adventitious root gravitropism", "body": "AbstractBackgroundThe close planting of dwarfing self-rooted rootstocks is currently a widely used method for apple production; however, self-rooted rootstocks are weak with shallow roots and poor grounding. Therefore, understanding the molecular mechanisms that establish the gravitropic set-point angles (GSAs) of the adventitious roots of self-rooted apple stocks is important for developing self-rooted apple rootstock cultivars with deep roots.ResultsWe report that the apple FOUR LIPS (MdFLP), an R2R3-MYB transcription factor (TF), functions in establishing the GSA of the adventitious roots of self-rooted apple stocks in response to gravity. Biochemical analyses demonstrate that MdFLP directly binds to the promoters of two auxin efflux carriers, MdPIN3 and MdPIN10 , that are involved in auxin transport, activates their transcriptional expression, and thereby promotes the development of adventitious roots in self-rooted apple stocks. Additionally, the apple auxin response factor MdARF19 influences the expression of those auxin efflux carriers and the establishment of the GSA of adventitious roots of apple in response to gravity by directly activating the expression of MdFLP .ConclusionOur findings provide new insights into the transcriptional regulation of MdFLP by the auxin response factor MdARF19 in the regulation of the GSA of adventitious roots of self-rooted apple stocks in response to gravity."}, {"tab": "tab_2", "article_id": "72587400", "url": "http://dx.doi.org/10.1186/s12870-019-1847-2&quot;, "reference": "Reference: (2019-05-30). Transcriptional regulation of MdPIN3 and MdPIN10 by MdFLP during apple self-rooted stock adventitious root gravitropism, Available at: http://dx.doi.org/10.1186/s12870-019-1847-2 Last Accessed: [03-06-19]", "notes": "", "title": "Transcriptional regulation of MdPIN3 and MdPIN10 by MdFLP during apple self-rooted stock adventitious root gravitropism", "body": "AbstractBackgroundThe close planting of dwarfing self-rooted rootstocks is currently a widely used method for apple production; however, self-rooted rootstocks are weak with shallow roots and poor grounding. Therefore, understanding the molecular mechanisms that establish the gravitropic set-point angles (GSAs) of the adventitious roots of self-rooted apple stocks is important for developing self-rooted apple rootstock cultivars with deep roots.ResultsWe report that the apple FOUR LIPS (MdFLP), an R2R3-MYB transcription factor (TF), functions in establishing the GSA of the adventitious roots of self-rooted apple stocks in response to gravity. Biochemical analyses demonstrate that MdFLP directly binds to the promoters of two auxin efflux carriers, MdPIN3 and MdPIN10 , that are involved in auxin transport, activates their transcriptional expression, and thereby promotes the development of adventitious roots in self-rooted apple stocks. Additionally, the apple auxin response factor MdARF19 influences the expression of those auxin efflux carriers and the establishment of the GSA of adventitious roots of apple in response to gravity by directly activating the expression of MdFLP .ConclusionOur findings provide new insights into the transcriptional regulation of MdFLP by the auxin response factor MdARF19 in the regulation of the GSA of adventitious roots of self-rooted apple stocks in response to gravity."}]

如何解决此问题


Tags: andoftheinselfdividapple