2016-09-18 14 views
0

フォームを1つの項目を提出すると考えられます投稿AJAX投稿、 投稿したときにフォームが送信されて初めて数回白AJAX item +値はENUMドロップダウンリスト から残りのアイテムの値はNUllですので、モデルは有効ではありません&その後、アイテムajaxが投稿すると思われるアイテムをすべて取得しています... スクリプトのリストIページを持っている:私は私のコントローラに(ポスト)を提出したいものを は値です 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>
0 LAT

<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> 
+0

多くの問題があります。 'lat'は' addShowCoords() 'で定義されていません。 'init()'の中でパラメータを指定せずに呼び出すと、 'geocodeAddress()'の中で再び呼び出されますが、パラメータは渡しますが、関数はそれを何もしません。また、イベントリスナーを呼び出すたびに追加します。また、 'async:false'を使わないでください。これはひどい習慣であり、ブラウザでは推奨されません。コンソールに関する警告が表示されるはずです。 – charlietfl

+0

あなたのコードでコンソールログを使用してデバッグする方法を学んでください。デバッガで – charlietfl

答えて

0

複数の提出は、あなたが何度も邪魔にならないjqueryの多くをロードするので、あなたのプロジェクト全体をチェックして、唯一の控えめなのjQueryを追加する場合にのみ発生します。

詳細については、click here

関連する問題