我有正由AJAX調用JavaScript文件中的小PHP服務:服務PHP Rails中
$.ajax({
type: "GET",
url: "getDate.php",
dataType:"json",
data :{
fromDate:fromDate,
toDate:toDate
},
success: function(data) {
......
}
});
此服務包含:
$fromDate = $_GET['fromDate'];
$toDate = $_GET['toDate'];
$fromDate=date_create($fromDate);
$fromdate = date_format($fromDate,"Y-m-d")."T".date_format($fromDate,"H:i:s")."Z";
$fromdate = urlencode($fromdate);
$toDate=date_create($toDate);
$todate = date_format($toDate,"Y-m-d")."T23:00:00Z";
$todate = urlencode($todate);
$url = "http://194.209.53.19:8086/query?db=Bellevue&q=select+*+from+measures+where+time%3E%3D%27".$fromdate."%27+and+time%3C%3D%27".$todate."%27";
$data = file_get_contents($url, false);
echo $data;
我需要在我的Rails使用此應用。我想知道我是否可以將.php文件放在Rails文件夾中,並簡單地調用它。或者如果有辦法在Rails中做類似的服務?
感謝你,看起來很容易做!我現在的問題是,我不知道date_create,date_format等的Rails等價物。你有鏈接還是可以提供給我的東西? – Komarzer
我已經更新了我的答案。如果你認爲我的回答是有效的,並幫助你,你可以接受它。 –
它通過使用strftime工作,謝謝。我接受了你的答案。 – Komarzer