calling functions from javascript code
I am using EM1000 platform with TIDE 2.6.22.
Is there any suggested way to interact javascript code with basic code? What I want to do is, to call a basic language written function when for example a button is clicked without posting to a new html site. In other ways i want to call a basic language written function from a javascript function . My aim is not to refresh the whole html site for just a function call. Currently i found a hack for this using XMLHttpRequest. Is there a known, better way ? Thank you in advance!
The more people who ask this question, the more it gets noticed.
-
Inappropriate?I am curious, does XMLHttpRequest work with Tibbo's webserver?
-
Inappropriate?yes, it seems working. up to now i did not notice any problems. if you want i can provide you the source codes.
-
Inappropriate?I believe that XMLHttpRequest is the way that is employed for AJAX, which is probably the most used way to achieve what you are doing. I just never thought that it might work with Tibbo's webserver. I am interested in finding out how it is done (since I am not that familiar with XMLHttpRequest).
-
Inappropriate?Can you provide me a source of your AJAX aplication?
-
Inappropriate?Hi,
Below is the source. What i am doing is, if the user clicks on an image on the html file, a js function (on_off(device)) is called where AJAX is implemented. Then the tibbo basic functions (which are in post.html) are called with the parameters passed from the html part.
This is the main html file:
This is post.html:
<?include "global.tbh"
dim http_req_string as string
dim device as byte
http_req_string = sock.httprqstring
device = val(get_http_argument (http_req_string,"device="))
process_node(device)
?> -
Inappropriate?main.html file was embedded to the answer :) so i removed script tags.post.htm is ok as above
this is java script part of main.html:
function on_off(device)
{
req=false;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest;
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.onreadystatechange = processReqChange2;
req.open("GET", "post.html" + '?device=' + device, true);
// req.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
req.send(null);
} else {
alert("Your browser does not support XMLHttpRequest technology!");
doesNotSupport = false;
}
}
function processReqChange2() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK" alert('ok');
if (req.status == 200) {
} else {
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
in the html part i put some images:
img src="on0.GIF" onmouseup = "on_off(0)"
img src="on1.GIF" onmouseup = "on_off(1)"
img src="on2.GIF" onmouseup = "on_off(2)" -
Inappropriate?Thank you, It's very useful, but I have one additional question, it ios possible to generete response for ex. in xml or plain text? I'm trying use plain text, but in IE it doesnt, work only in Firefox.
in index.html
function handleServerResponse()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
xmldoc = xmlHttp.responseText;
document.getElementById("divMessage").innerHTML = "Preasure: " + xmldoc + "hPa";
setTimeout('process()', 2000);
}
}
in query file i have this:
<?
include "global.tbh"
sock.setdata(get_preasuer()) 'generate info for ex. 1005
sock.send
?>
Loading Profile...




