當我試圖在這種語言中找到一些基礎時,我對jQuery有點慢。我目前正在與FaceAPI合作,我的工作非常棒。在識別階段,我有一個返回信息數組的Ajax調用。時間戳被返回的變量
$.ajax({
url: 'http://api.face.com/faces/recognize.json?&uids=all&namespace=camera_app&detector=Aggressive&',
data: formdata,
cache: false,
contentType: false,
processData: false,
dataType:"json",
type: 'POST',
success: function (data) {
photo = data.photos[0];
handleResult(photo)
},
但我最感興趣的是被稱爲API的「UID」將人的面部匹配到他們的UID。我想知道的是,一旦UID返回,可以將時間戳放置並保存到我已設置的數據庫中? [旁註:用戶照片只提交給API,我不保存在我的數據庫中。只有我保存的是用戶名/姓和UID。]我只是不知道timestamp函數如何與返回變量一起工作。
我希望能夠在稍後的日期提取該信息返回時的UID和時間戳匹配。
更新:
這裏就是UID和準確性(置信度)被顯示給用戶:
function handleResult(photo) {
console.log(photo)
var s = "<h2 class='results'>Account Information:</h2>";
if(photo.tags.length) {
var tag = photo.tags[0].uids[0];
s += "<p>";
//$('#result') .html ('Welcome Back:' + photo.uid + ',' + 'Confidence:' + photo.confidence);
if(tag.uid) s += "<li> User:" + tag.uid + "</li>";
if(tag.uid) s += "<li> Accuracy:" + tag.confidence + "%" + "</li>";
if(tag.uid == 0) s += "I got something, but the data wasn't clear. Sorry.";
} else {
s += "<p>Sorry, I didn't find any faces.</p>";
}
$("#result").html(s);
在這個階段,我想一個時間戳被創建。
解決:
function handleResult(photo) {
console.log(photo)
var s = "<h2 class='results'>Account Information:</h2>";
var month = new Date().getMonth() + 1;
var day = new Date().getDate();
var hours = new Date().getHours();
var min = new Date().getMinutes();
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (min < 10)
min = "0" + min
if(photo.tags.length) {
var tag = photo.tags[0].uids[0];
s += "<p>";
//$('#result') .html ('Welcome Back:' + photo.uid + ',' + 'Confidence:' + photo.confidence);
if(tag.uid) s += "<li> User:" + tag.uid + "</li>";
if(tag.uid) s += "<li> Accuracy:" + tag.confidence + "%" + "</li>";
if(tag.uid) s += "<li> Timestamp:" + month + "/" + day + " " + hours + ":" + min + suffix + "</li>";
if(tag.uid == 0) s += "I got something, but the data wasn't clear. Sorry.";
} else {
s += "<p>Sorry, I didn't find any faces.</p>";
}
$("#result").html(s);
什麼在您的數據庫中輸入時間戳與第三方API的Ajax調用有關? – charlietfl
我想要完成的是在上面的識別調用期間uid從FaceAPI返回的時間。 – shayward
只需使用javascript日期對象創建一個 – charlietfl