Hello,
I am working on lwip webserver. The code for the webserver is in C language. I want to create a dynamic webpage that displays the value of the 32-bit system register according to my application.
In my case, I have created a const char [ ] that has html code inside and I pass it in tcp_write( ) and the web page gets displayed! It works. I have also created javascript code in the html code itself that dynamically changes the content on the webpage through button onclick event. However, I want this to be change using the C variable in my code. So, how do I link the C global variable or local variable to the javascript?
In simpler way, I tried to declare a global variable say UINT a=10. Then, on button onclick event, when javascript is executed, I tried to change the content on webpage using the variable “a”. But it doesn’t work!
Does anyone knows how to make my C code and javascript code work together?
For reference, I am attaching the html and javascript code below:
const char testdata[]= “<html>
<body>
<button onclick=”start()”> Start the countdown </button>
<p id=”demo”> This the main page for the test application of the web server…</p>
<p id=”ch1″> Change me with variable a…</p>
<div id=”bip”>
</div>
<script>
var counter = 10;
var intervalId = null;
function finish()
{
clearInterval(intervalId);
document.getElementById(“bip”).innerHTML = “THE END!”;
if(counter == 0) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
document.getElementById(“demo”).innerHTML =
this.responseText;
}}
}
xhttp.open(“GET”, “ajaxinfo.txt”, true);
xhttp.send();
}
function bip()
{
if(counter == 0) finish();
else {
document.getElementById(“bip”).innerHTML = counter + ” seconds remaining”;
}
counter–;
}
function start() { intervalId = setInterval(bip, 1000);}
</script>
</body>
</html>”;
I want to replace any <p> element with a global variable that will be declared in the C code that has this html code inside a const char array as shown above.
Any help is highly appreciated.
Thanks,