0
有一个表单中的一个项目是假设提交查看AJAX帖子, 但是当我发布表单提交几次白色在第一次它只提交AJAX ENUM下拉列表中的项目+值, 和其余项目值是NUll,因此该模型无效&之后,我收到除了项目ajax假设发布的所有项目... 脚本I的列表在该页面: 我希望提交(邮寄)到我的控制器值:LAT ajax后导致我的表单多次提交
<script src="/Scripts/modernizr-2.8.3.js"></script>
<script src="/Scripts/jquery-3.1.0.js"></script>
<script src="/Scripts/jquery-ui-1.12.0.js"></script>
<script src="/Scripts/underscore-min.js"></script>
<script src="/Scripts/moment.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/respond.js"></script>
<script src="/Scripts/GenresScripts.js"></script>
<script src="/Scripts/bootbox.min.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script type="text/javascript">
var map;
var initialCenter;
var initialZoom;
var elevationService;
var geocoder;
function init() {
var mapOptions = {
center: new window.google.maps.LatLng(52.373922, -3.427734),
zoom: 14,
mapTypeId: window.google.maps.MapTypeId.TERRAIN,
mapTypeControl: false
};
map = new window.google.maps.Map(document.getElementById('mapDiv'), mapOptions);
initialCenter = mapOptions.center;
initialZoom = mapOptions.zoom;
addGeocodingService();
addShowCoords();
}
google.maps.event.addDomListener(window, "load", init);
function addGeocodingService() {
geocoder = new window.google.maps.Geocoder();
}
function geocodeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode({ 'address': address },
function(results, status) {
if (status === window.google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
addShowCoords(results[0].geometry.location);
//var position = results[0].geometry.location;
} else {
alert("Geocode failed with the following error: " + status);
}
});
};
function addShowCoords() {
window.google.maps.event.addListener(map,
'center_changed',
function() {
var newCenter = map.getCenter().toString();
var lat = newCenter.toString();
document.getElementById('LatLong').innerText = lat;
});
$.ajax({
type: "POST",
//ActionName
url: "Create",
//Just for test hard code value
//Should be : data: { LatLong:lat},
data: { LatLong: lat },
async: false,
datetype: "html",
success: function (data) {
$('#result').html(data);
return false;
},
error: function() {
alert("oops, something bad happened");
}
});
};
</script>
您有许多问题。 ''lat'在addShowCoords()中未定义。你可以在不带参数的'init()'内部调用它,然后在'geocodeAddress()'中再次调用它,但是传入参数,但函数不会执行任何操作。每次调用它时还要添加事件监听器。也不要使用'async:false'这是一个可怕的做法,并且已被浏览器所弃用,并且您应该在控制台中看到关于该错误的警告 – charlietfl
建议您学会在代码中使用控制台日志记录进行调试..或学习如何使用断点在调试器中 – charlietfl