how can I sent value to JSP by javascript?
I want to sent latitude and longitude parameters to JSP

<body>
<button onclick="getLocation()">click</button>
<script>
function getLocation() {

if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(displayLocation);
else
alert("Oops, no geolocation support");
}

function displayLocation(position) {

var latitude = position.coords.latitude;       // ดึงเอาค่า lat
var longitude = position.coords.longitude;  // ดึงค่า long

}

</script>

</body>

I don't know what form i should do
thnk you very much!

Recommended Answers

All 6 Replies

You need a JSP script that will receive the data either via HTTP GET or POST.

Do you want to interact with this JSP page/script via postback or behind the scenes using AJAX?

You reference a link that covers asp.net not jsp.

In any case, I'd recommend you use javascript to pass the parameters using Ajax back to the JSP page. You can do this easily using the jQuery library.

http://api.jquery.com/jquery.post/

You'd have to be comfortable with HTML and basic JavaScript to be able to incorporate jQuery in your page.

thnkyou veru muchhhh!!!

Or even better learn Wicket framework

You need AJAX request to sent to your backend

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.