網頁端利用jquery提供的高階javascript方法getJSON或ajax取用其他網頁服務的寫法,資料傳收過程皆採用json格式:
$.getJSON( "http://host:port/path",
{bookID:"1309088",format:"json"})
.done(function( data ) {
var output = "";
for(var i in data.items){
output ="<li>" + data.items[i].value + "," + data.items[i].id + "," + data.items[i].name + "</li>\n";
$('#result').append(output);
}
})
.fail(function() {
window.alert("fail");
});
//--
$.ajax({
url: 'http://host:port/path', //存取Json的網址
type: 'post',
cache:false,
dataType: 'json', // format expected from server
contentType: 'application/json; charset=utf-8', // format sent to server
data: JSON.stringify({bookID:"1309088}),
success: function (data) {
html = '<table>';
i=1;
$.each(data, function () {
html += '<tr><td>' + data[i]['model'] + '</td>'
' + data[i]['epoch'] + '</td></tr>\n';
i++;
});
html += '</table>';
document.getElementById("list_model").innerHTML = html;
},
error: function (xhr, ajaxOptions, thrownError) {
document.getElementById("result").innerHTML =
'internal error(' + xhr.status + ',' + thrownError + '), try again...';
}
});
jquery getJSON and ajax functions for calling JSON-based web services
訂閱:
張貼留言 (Atom)
how to deal with metric scale inconsistency in topn recommendation evaluation
🎯 推薦系統一般會回傳前 N 個排名的物品清單給用戶,稱為 Top‑N 推薦。 遇到推薦模型須要訓練及評估時,習慣先蒐集用戶與物品的互動資料,再將資料拆分成沒有重疊的訓練集及測試集。 模型在訓練時只看得到訓練集,評估時則拿測試集作為驗證的標準答案,以免作...
沒有留言:
張貼留言