2017-10-13 5 views
0

以下は私のコードです。返すようにアラートを変更してボタンをクリックすると、結果は表示されません。私はボタンをクリックすると警告部分を変更する方法を教えてください、それはページのjson結果を返す必要があります。どうもありがとうございます!WebForm json結果へのアラートボックスの結果を変更する方法

<script type="text/javascript"> 
<!-- 
function GetLocation() { 
    var geocoder = new google.maps.Geocoder(); 
    var address = document.getElementById("txtAddress").value; 
    geocoder.geocode({ 'address': address }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      var latitude = results[0].geometry.location.lat(); 
      var longitude = results[0].geometry.location.lng(); 
      alert("Latitude: " + latitude + "\nLongitude: " + longitude); 
     } else { 
      alert("Request failed.") 
     } 
    }); 
}; 
    //--> 
</script> 
+0

「json結果をページに戻す」と言ったらどういう意味ですか? divにJSONデータを表示しますか?または何? –

+0

オリジナルのコードのようにボタンをクリックすると、警告ボックスが表示されます。結果はボックスの内側になります。しかし、私は、ページではない警告ボックスに表示されたいと思います。 –

答えて

0

私はあなたのHTMLコードがどのようなものか知らないので、私はdivに表示する例をあげます。

<body> 
    <button onclick="GetLocation()">Click me</button> 
    <div id="resultdata"></div> 
</body> 

そしてresultdataに表示するには、このようなinnerHTMLを使用することができます。

<script type="text/javascript"> 
function GetLocation() { 
    var geocoder = new google.maps.Geocoder(); 
    var address = document.getElementById("txtAddress").value; 
    geocoder.geocode({ 'address': address }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      var latitude = results[0].geometry.location.lat(); 
      var longitude = results[0].geometry.location.lng(); 
      //get JSON data. 
      var JSONData = JSON.stringify({"Latitude": latitude, "Longitude": longitude}); 
      document.getElementById("resultdata").innerHTML = JSONData; 
     } else { 
      alert("Request failed."); 
     } 
    }); 
}; 
</script> 

このヘルプが必要です。

+0

ありがとう –

関連する問題