查询范围返回空

时间:2015-11-30 21:28:56

标签: jquery sql json soql

我正在构建一个简单的查询,以根据记录的创建日期恢复一些数据:

function buildQuery(startDate, endDate)
{
    var start_date = formattedDate(startDate);  //YYYY-MM-DD
    var end_date = formattedDate(endDate);      //YYYY-MM-DD
    var c_type = 'Noise';                                          // Complaint Type

    // Build the data URL
    URL = "http://data.cityofnewyork.us/resource/erm2-nwe9.json"; // API Access Endpoint
    URL += "?";                                                   // A query parameter name is preceded by the question mark
    URL += "$where=";                                             // Filters to be applied
    URL += "(latitude IS NOT NULL)";                              // Only return records with coordinates
    URL += " AND ";
    URL += "(complaint_type='" + c_type + "')";                    // Desired complaint
    URL += " AND ";
    URL += "(created_date>='" + start_date + "') AND (created_date<='" + end_date + "')"; // Date range
    URL += "&$group=complaint_type,descriptor,latitude,longitude";                        // Fields to group by
    URL += "&$select=descriptor,latitude,longitude,complaint_type";                       // Fields to return
    URL = encodeURI(URL);                                                                 // Encode special characters such as spaces and quotes
}

当我使用startDate = endDate时,无论它是什么日期,我使用以下代码获得的结果 .json 都会返回空白。

$.getJSON(URL, function(data)

但是,如果我检查:

  

http://data.cityofnewyork.us/resource/erm2-nwe9.json

有与特定日期匹配的记录。 例如,当startDate和endDate都等于2015-11-29时会发生这种情况。

1 个答案:

答案 0 :(得分:0)

@Rabbit似乎是正确的 - 返回的数据包含"created_date" : "2015-11-30T02:14:24",表示“日期”有一个时间组件。更改代码的这两行:

var start_date = formattedDate(startDate)+"T00:00:00";  //YYYY-MM-DDThh:mm:ss
var end_date = formattedDate(endDate)+"T23:59:59";      //YYYY-MM-DDThh:mm:ss