如何将Txt文件密钥和实体值链接到javascript?

时间:2017-04-27 04:24:16

标签: javascript

我目前正在制作活动日历。其中我必须从外部txt文件将事件添加到日历中。如何将键值和实体链接到JavaScript?应该根据我在txt文件中给出的内容正确显示事件。 提前感谢,

Code:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<link rel='stylesheet' href='../lib/Theme/jquery-ui.min.css' />
<link href='../fullcalendar.min.css' rel='stylesheet' />
<link href='../fullcalendar.print.min.css' rel='stylesheet' media='print' />
<script src='../lib/moment.min.js'></script>
<script src='../lib/jquery.min.js'></script>
<script src='../fullcalendar.min.js'></script>
<li src='../events.txt'></li>
<script>
   $(document).ready(function() {
      $('#calendar').fullCalendar({
            theme: true,
            header: {
                right: 'prev,next today',
                center: 'title',
                left: 'month,agendaWeek,agendaDay,listMonth'
            },
            defaultDate: '2017-04-12',
            navLinks: true, // can click day/week names to navigate views
            eventLimit: true, // allow "more" link when too many events

            events: [
            {
                    title: ' ',
                    start: ' '
                }
            ]
        });

    });
[Txt file][1]

[1]: https://drive.google.com/open?id=0Bw3XnR8_0rzCVEpVMlpHNm41bUk

1 个答案:

答案 0 :(得分:0)

使用jQuery's AJAX

$.ajax({
    url: "sometext.txt",
    success: function(data) {
       processData(data);
    },
    error: function(xhr) {
       console.log("Something broke.");
    }
})

我建议将数据存储在JSON中,以便不需要进一步处理。像这样:

[
    {
        "title": "Probosys Meeting",
        "start": "2017-04-01"
    },
    {
        "title": "Probosys Starting",
        "start": "2017-04-03"
    },
    {
        "title": "Probosys Fucntion",
        "start": "2017-04-06"
    }
]