Passing a value using Ajax to an exe then back
Posted: Sat Jun 13, 2020 9:59 am
I am stumped and I am sure this should be simple for someone who knows about Ajax.
I am trying to pick up a value entered by a user on a basic webpage, pass it to an exe (written in PureBasic) and just have the value passed back to the page where it is displayed. I can do this using CGI with a form statement but I do not want a new page generated.
I have a very simple webpage called 'test.htm'.
I think the problem is with the html page. When I get this to work I then want to have the exe call a Sqlite database, do a query, then return data that can be placed at a spot on the page. But for now this is just a test.
Thanks to anyone who can straight me out.
The CGI program is testvalue.pb compiled to testvalue.exe.
Here is the testvalue.pb code:
And here is the html code for the test.htm page:
I am trying to pick up a value entered by a user on a basic webpage, pass it to an exe (written in PureBasic) and just have the value passed back to the page where it is displayed. I can do this using CGI with a form statement but I do not want a new page generated.
I have a very simple webpage called 'test.htm'.
I think the problem is with the html page. When I get this to work I then want to have the exe call a Sqlite database, do a query, then return data that can be placed at a spot on the page. But for now this is just a test.
Thanks to anyone who can straight me out.
The CGI program is testvalue.pb compiled to testvalue.exe.
Here is the testvalue.pb code:
Code: Select all
;compile to testvalue.exe
If Not InitCGI() Or Not ReadCGI()
End
EndIf
Content$="?"+CGIVariable(#PB_CGI_QueryString)
Value$=GetURLPart(Content$,"itemnumber")
a$=Content$+"<br>"+"<br>"+Value$+"<br>" ;this is what is to be passed back to the calling page
WriteCGIHeader(#PB_CGI_HeaderContentType,"text/html",#PB_CGI_LastHeader)
WriteCGIString(a$)
Code: Select all
<html>
<body>
<label for="fname">Item number:</label>
<input type="text" id="fname" name="itemnumber"><br><br>
<button type="Submit" onclick="loadDoc(this.value,myFunction)">Try it</button>
<br>
<br>
<p id="demo">
</p>
<script>
function loadDoc(val,cFunction) {
var xhttp;
if (str=="") {
document.getElementById("fname").innerHTML="";
return;
}
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
cFunction(this);
}
};
var a=="http:testvalue.exe?"+document.getElementById("fname")+"="+val
xhttp.open("GET", a, true);
xhttp.send();
}
function myFunction(xhttp) {
document.getElementById("demo").innerHTML =
xhttp.responseText;
}
</script>
</body>
</html>