如何在服务器上上传json文件?

时间:2016-08-19 00:56:50

标签: javascript html json ajax

我有一个名为" datetime.json"的json文件。返回服务器的当前日期和时间,我已将文件上传到我的Web主机服务器上。

当我通过AJAX在我的网站项目上调用它时,它不会返回我的webhost服务器的当前日期和时间。而且我也希望将时间和日期格式化为这样的

Time: "hh:mm:ss AM/PM",
Date: "08/19/2016

这是我的JSON文件:

[
  {
    date: '{{date(new Date("08/18/2016"))}}',
    time : '{{date(new Date("08:22:43 AM"))}}',
     timeZone: "Asia/Singapore"
    }
 ]

更新: 好的,我编写了PHP文件,它返回了我服务器的当前时间和日期 http://cgbp.org/date.php

如何通过客户端的Ajax请求提取时间和日期内容? $就({     dataType:' json',     网址:' http://cgbp.org/date.php',     成功:功能(结果){       var InternetDate = new Date(result.date);        var monthNames = [                                                  " 1月"," 2月"," 3月",                                                  " April"," May"," June"," July",                                                  "八月","九月","十月",                                                  " 11月"," 12月"                                                ];

                                           var weekday = new Array(7);
                                           weekday[0]=  "Sunday";
                                           weekday[1] = "Monday";
                                           weekday[2] = "Tuesday";
                                           weekday[3] = "Wednesday";
                                           weekday[4] = "Thursday";
                                           weekday[5] = "Friday";
                                           weekday[6] = "Saturday";

                                           var dayofweek = weekday[InternetDate.getDay()]; 
                                           var day = InternetDate.getDate();
                                           var monthIndex = monthNames[InternetDate.getMonth()];
                                           var year = InternetDate.getFullYear();


    //document.getElementById('time').innerHTML = dayofweek +', '+ monthIndex +' '+ day +', '+ year;
    document.getElementById('time').innerHTML = result.datecontents;
    document.getElementById('curdate').value = result.date;
}

});

0 个答案:

没有答案