開発初心者はここにあります。私は自分のウェブサイト上のGoogleマップ上の各インフォボックス内にフォームを作成しようとしています。私はすべてのマーカーとそれぞれのマーカーの内容を生成する1つの関数を持っています。インフォボックス内にajaxを含むフォームを送信するGoogleMaps API
私の問題は、infowindow内のフォームの後に呼び出されるjQueryが呼び出されないことです(少なくともaddComment.phpは呼び出されません)。私は多くを見回し、この問題を解決するための何も見つけることができませんでした。すべてのヘルプは非常にその後
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: new google.maps.LatLng(38.64806723893503, -90.30880584275044),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var pdata;
$.ajax({type:'POST', url: 'fetchInfo.php', data: pdata, dataType: 'json', success: function(response) {
var infowindow = new google.maps.InfoWindow();
var marker, i;
var content = new Array();
for (i = 0; i < response.length; i++) {
content[i] = '<div> '+ response[i].added;
content[i] += '<div class=description>'+response[i].desc+'</div>';
content[i] += '</div>';
content[i] += '<div class=addCom>';
content[i] += '<textarea rows="4" cols="10" name="comment" id="comment" data-picId='+response[i].picture_id+' placeholder="Enter Comment Here..."></textarea><br>';
content[i] += '<input class="submitComment" type="button" value="Add Comment"/>';
content[i] += '</div>';
marker = new google.maps.Marker({
position: new google.maps.LatLng(response[i].lat, response[i].lng),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
map.panTo(marker.position);
infowindow.setContent(content[i]);
infowindow.open(map, marker);
}
})(marker, i));
}
}});
をいただければ幸い、この機能とは別に、私はあなたのスクリプトを見ていることでAJAX呼び出し
$(".submitComment").click(function(){
var comment = $("#comment").val();
var picture_id = $(this).attr('data-picId');
var user_id = usrId;
if (comment === ""){
return;
}
var pdata = {
comment : comment,
picture_id : picture_id,
user_id : user_id
};
$.ajax({type:'POST', url: 'addComment.php', data: pdata, dataType: 'json', success: function(response) {
if(response.success){
$("#uploadfile_input").val("");
$("#lat").val("");
$("#lng").val("");
$("#desc").val("");
load();
}
}
});
});