フォームを送信する前に、フォームに挿入されたアドレスのlat longを取得しようとしています。Jqueryフォーム送信、非同期呼び出し、成功時フォーム送信
var success = false;
var getLat = 0;
var getLng = 0;
function getLngLat() {
var address = $(".save-new-address").val();
if(!address) return false;
if(success) return false;
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log(results);
map.setCenter(results[0].geometry.location);
success = true;
var newMarker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
$(".save-new-lat").val(results[0].geometry.location.lat);
$(".save-new-lng").val(results[0].geometry.location.lng);
} else {
alert("Geocode was not successful for the following reason: " + status);
};
});
}
$("form#save-new-restaurant").submit(function() {
getLngLat();
if(success) {
return true;
} else {
getLngLat();
$("form#save-new-restaurant").submit();
return false;
}
});
それのほとんどは、単にGoogleの開発者ページからコピーされます。
は、ここに私のコードです。しかし、私が見つける午前はあるのいずれかの形があまりにも速い提出され、その詳細は上記の関数が終了した後に取得した、私はちょうどフォームが送信されるグーグルからデータを取得しようとしています
、とされています私はのデータを持っています。私はフォームを送信したいと思います。これどうやってするの?
これはうまくいきました!ありがとうございました! – Chud37