jQuery with Yun ?

Hi there,

I have the bridge.ino loaded in the Yun. (witch works fine).
And an HTml page who interacts with it (Yun)

I would like to “make simpler” my ajax functions, can it be done, with jQuery?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta http-equiv="author" content="Rui Pereira">
<meta http-equiv="description" content="Controlo Remoto da Casa">
<meta http-equiv="refresh" content="15">
<title>Projecto ISCIA-1</title>
<script language="Javascript">

function xmlhttpPost(strURL) {
	  var xmlHttpReq = false;
	  var self = this;
	  // Mozilla/Safari/firefox/chrome
	  if (window.XMLHttpRequest) {
			self.xmlHttpReq = new XMLHttpRequest();
	  }
	  // Internet Explorer
	  else if (window.ActiveXObject) {
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  self.xmlHttpReq.open('POST', strURL, true);
	  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	  self.xmlHttpReq.onreadystatechange = function() { if (self.xmlHttpReq.readyState == 4) { updatepage(self.xmlHttpReq.responseText); }
	  }
	  self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
	var form     = document.forms['casa'];
	var valor = form.assoalhada.value;
	qstr = 'assoalhada=' + escape(valor);  // NOTE: no '?' before querystring
	return qstr;
}
function updatepage(str){
	document.getElementById("estado").innerHTML = str;
}
</script>
..
..
..
..
<input type="button" class="bg-primary" onclick='JavaScript:xmlhttpPost("/arduino/analog/5")' value="Read">

It was told, that with jQuery, was less confuse and a shorter code…

So i tried this, (but i’m not very good with javascript)

<html lang='pt-pt'>
        <head>
                <script src='./jquery-3.4.1.js'></script>
                 <script>
                        $(document).ready(function(){
                                fazerLeitura();
                        });
                        ////////////////////////////////////////////
                        function extrairValor(leu){
                                var resultado=leu;
                                resultado= $.('#res');
                        }
                        ////////////////////////////////////////////
                        function fazerLeitura(){
                                $.get('/arduino/analog/5',extrairValor(leitura));
                        }
                 </script>
        </head>

        <body>
                <div id='resultado'>  </div>
        </body>
</html>

but doesn’t work…
Does anyone knows how to overcome this?

Thank’s in advance.
Rui

PS i have a sharp IR sensor in analog in pin 5, and a solid state relay in digital out 13.
but i wanna do the readind and the writing in the web page. (not in the bridge C program. )

Hello there,

Does anyone here ever used jQuery to send URL commands to the Yun?
Somebody can send me, a clue, “heads up” ?

Thanks in advance.