Reputation: 563
I have a webpage that loads and runs jquery once the page is ready, like this:
$(document).ready(function () {
navigator.geolocation.getCurrentPosition(showPosition, positionError);
function showPosition(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById('div_latitude').innerHTML = latitude;
document.getElementById('div_longitude').innerHTML = longitude;
}
function positionError(position) {
alert("Error: " + position.code);
}
});
After I have assigned the div_latitude and div_longitude their values, I want to run code that will use this information automatically. How can I make sure this second piece of code will run after the jquery?
Upvotes: 1
Views: 513
Reputation: 541
You will have to make an ajax call to communicate to the server side code so that you can pass the vales you needed after jQuery is loaded.
Code is as follows. $(document).ready(function () { navigator.geolocation.getCurrentPosition(showPosition, positionError);
function showPosition(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById('div_latitude').innerHTML = latitude;
document.getElementById('div_longitude').innerHTML = longitude;
}
function positionError(position) {
alert("Error: " + position.code);
}
makeAjaxCall();
});
function makeAjaxCall()
{
$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Ajax Call Successfull.
}
});
}
Upvotes: 1
Reputation: 21
You might like to check status in jquery as "complete" and you can make an AJAX call to C# codes you want to execute.
Upvotes: 1