У меня есть следующий код в <head>
, который имеет переменные (emp.longitude
и emp.longitude
), которые мне нужно получить:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
async: false,
url: 'GetRecords.asmx/GetValues',
dataType: "json",
method: 'post',
success: function (data) {
var employeeTable = $('#tblEmployee tbody');
employeeTable.empty();
$(data).each(function (index, emp) {
employeeTable.append('</td><td>'
+ emp.latitude + '</td><td>' + emp.longitude + '</td><td>');
});
},
error: function (err) {
alert(err +" fail");
}
});
});
</script>
В <body>
есть другой скрипт, где мне нужно использовать эти переменные:
<script>
var mymap = L.map('mapid').setView([38.8, -94.8], 5);
// need to use them below (longitude and latitude)
L.marker([longitude,latitude], { icon: truckIcon }).addTo(mymap).bindPopup("I am here!");
var popup = L.popup();
function onMapClick(e) {
popup
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(mymap);
}
mymap.on('click', onMapClick);
</script>
У меня уже есть таблица, которая выводит эти значения в <body>
<form id="form1" runat="server">
<div class="container">
<h3 class="text-uppercase text-center">How to retrive data using ajax in asp.net</h3>
<table id="tblEmployee" class="table table-bordered">
<thead class="bg-primary text-white">
<tr>
<th>latitude</th>
<th>longitude</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</form>
Любые идеи, как я могу получить эти переменные из функции в голове и использовать их в другом сценарии в теле. Благодарю.