jquery と serialize メソッドに問題があります。
メソッドを介して送信するフォームがあります$.ajax
。この方法では、 を使用しますserialize();
。serialize を呼び出す前に、2 つの入力テキスト値を変更する関数を使用しますが、2 つの入力をシリアル化すると古い値が送信されます。
これは私のコードです。
$('#formANAGRAFICA3').submit(function() {
codeAddress();
var $form = $('#formANAGRAFICA3');
$.ajax({
type: 'post',
data : $form.serialize(),
url: $form.attr( 'action' ),
success: function(data, textStatus, jqXHR) {
$('#editANAGRAFICA3').show();
}
});
return false;
});
function codeAddress() {
var address = 'my value';
geocoder.geocode( {'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var pos = results[0].geometry.location;
map.setCenter(pos);
marker.setPosition(pos);
document.getElementById("aTitle33").value = pos.lat();
document.getElementById("aTitle34").value = pos.lng();
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
関数で入力テキスト値を変更しても、フォームを送信すると、受信したデータが更新されませんcodeAddress
。なんで?