How to update values on my web page


I would appreciate some help with this…
I have a web page that is making a http request to agent, then the agent a device.send where I get a distance value. My question is how do I get that distance value which is inside the agent.on method, back to my onrequest method and then send it back to my web page?

`function requestHandler(request, response) {

dist = device.send("getDistance");

response.header("Access-Control-Allow-Origin", "*");


agent.on(“getDistance” {
local distance = 0;
distance = 29.1;
return distance; *** This return statement is not working


		function sendToAgent() {
			var data = $("#data")[0].value;
				url: "",
				data: "data="+data,
				method: 'POST',
				success: function(response) {
				   $("#response").html("Success - sent data to agent");
				 error: function (request, status, error) {
				   $("#response").html("ERROR - "+request.responseText);

<button name="data" id="data" onclick='sendToAgent()'>Get Distance</button>

<span id="response"></span>

Edit: Wrapped code in < code > </ code > tags.

On your webpage, you’re using PHP?


Oh, sorry, I’m not using PHP at this point. Would it be better if I was? Here is my web page code.


<br /><br /><br /><br /><br /><br /><br />
		<input type="text" name="data" id="data" value="mydata" />
		<button onclick='sendToAgent()'>Submit</button>

<span id="response"></span>

Edit: Wrapped code in < code > </ code > tags.

All the html code can’t be sent over this comment window, but all what I have is a button with an onclik even that calls the sendToAgent function.

This thread shows the best round trip method.

Thank you jwehr, I’m going to take a look.