私は ajax とサーブレットの間の要求/応答を処理しようとしています: ユーザーは Google マップ マーカーをクリックし、ajax を介して、ID を使用してマーカーに関連するコメントを呼び出します。
これは Ajax コードである必要があります
function infoCallback(infowindow, marker) {
return function() {
$.ajax({
type: 'POST',
url: 'commentListener',
data: {
id: marker.id,
comment:$('#comment').val()
},
success:function(data){
var comment = $('#output').html(data);
infowindow.setContent(comment);
infowindow.open(map, marker);
}
});
};
}
これはサーブレットコードである必要があります
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
long id = Long.parseLong(request.getParameter("id"));
String comment = //comment relative to the id
/*Way to send the comment to the infowindow*/
response.getWriter().write("{comment:"+comment+"}");
}
これがすべて明確でない場合は申し訳ありません!