-->
Page 1 of 1

[SOLVED] AJAX with ESPBasic (not need to refresh the page)

PostPosted: Tue Dec 15, 2015 10:43 pm
by tayfun
Hello, Good News! I love Basic :mrgreen:


first load index.htm and stable picture on file manager, then running basic code then

write browser "yourlocalip/file?file=index.htm" and bingo! :)

complate project link

http://www.newmaan.com/Load_File_Manager.rar



Basic Run

Code: Select allvar = 0
msgbranch [datayolla]
cls
print "Bir data girin = "
wait
[datayolla]
var = var + 1
msgget "data_kod" gelendata
print gelendata
let myReturnMsg = "geriyollanan kod = " & var
msgreturn myReturnMsg
wait




index.htm

Code: Select all<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0041)http://192.168.43.90/file?file=index.html -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link href="./index_files/sitil.css" rel="stylesheet" type="text/css">
<title>Ajax Refresh Uygulaması</title>

<script type="text/javascript">

var istek =false;

if (window.XMLHttpRequest)
{
   istek = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
   istek = new ActiveXObject("Microsoft.XMLHTTP");
}
setInterval(function(){
   istek.open("GET", "/msg?data_kod=Tayfun", true);
   istek.onreadystatechange = verileriAl;
   istek.send(null);
}, 500);





function verileriAl() {
   if (istek.readyState == 4 && istek.status == 200)
   {
      var cevap = istek.responseText;
      document.getElementById("sonuc").innerHTML = cevap;
      document.getElementById("sonuc").style.backgroundColor="#FF0061";
   }
}


</script>
</head>

<body><div align="center">
<div id="cerceve">
<div align="left">
<h1>Ajax Refresh</h1>
<img src="/file?file=not_reload_my_image.JPG" alt="Mountain View" style="width:304px;height:228px;">

<div id="sonuc" style="background-color: rgb(255, 0, 97);">geriyollanan kod = 19.00</div>
</div>
</div>
</div>
</body></html>


Re: [SOLVED] AJAX with ESPBasic (not need to refresh the pa

PostPosted: Wed Dec 16, 2015 7:23 am
by cwilt
Good job.

Should make it easy to display GPIO status without having to refresh the page.

Re: [SOLVED] AJAX with ESPBasic (not need to refresh the pa

PostPosted: Wed Dec 16, 2015 6:10 pm
by Mmiscool
Thank you so much for figuring this out. It really opes up the possibility of creating very polished fast applications.

Will be interesting to see some more of this.

On a side note html files uploaded to the device don't suffer from the same problems of html buffer getting filled up by the print command as the data is streamed directly off of the flash.