Hi Tom,
If the site you are trying to contact has CORS enabled appropriately, then you
can do something like this...
With the LiveCode browser widget, you can call JavaScript functions from LC
script and have the JavaScript functions call LC handlers in return.
JavaScript has the capability to perform asynchronous HTTP requests.
You can create a HTML page that you automatically load up in the browser widget
that has a small JavaScript function which you can call from LC with ‘do in
widget’. All this function needs to do is issue an asynchronous HTTP call to
the URL passed to it as a parameter and when it receives the data, return it
back to your LC script by calling a nominated LC handler and passing the
returned data as a parameter.
The HTML page would look something like this:
<html>
<head>
<title>Javascript Async Test</title>
<script type="text/javascript">
function httpGetAsync(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
liveCode.httpRequestComplete(theUrl, xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
</script>
</head>
<body>
</body>
<html>
You can either load that from a file into the browser widget’s URL or set its
htmlText property accordingly...
Then in LC, make sure you register the httpRequestComplete handler so that the
widget can call it:
set the javascriptHandlers of widget “browser” to “httpRequestComplete”
After that, add a httpRequestComplete handler to the card script to handle the
returned data:
on httpRequestComplete pUrl, pData
— pUrl will be the URL requested
— pData will be the data returned from the URL requested
end httpRequestComplete
Lastly, make your async requests....
do (“httpGetAsync(‘http://www.livecode.com’);” in widget “browser”
Since the JavaScript in the browser widget is issuing the requests and sending
the data back to LC, it doesn’t need to display anything related to it in the
browser widget itself - it can be a blank canvas.
Just be aware that the browser widget can cache URLs and there is no easy way
(that I know of?) in LC to clear the browser’s cache... so if you see very
quick responses on a second or subsequent request to the same URL, it is likely
pulling it all from the browser’s cache.
Cheers,
Charles
>> On 16 Mar 2018, at 1:35 pm, Tom Glod via use-livecode
>> <[email protected]> wrote:
>>
>> Great hints there Mike .... thanks alot. Luckily I'm desktop only right
>> now.
>>
>> It shouldn't be too long before I sit down to make something that I can
>> rely on and reuse in future projects.
>>
>> Might turn out I will have to hire someone to help which is cool too.
>>
>> It only has to be very simple..and does not need to match performance of
>> Tsnet.
>>
>> Anything more than 1 would be a great start. LOL.
>>
>> I will look into the libURL library and then try to guess which way I
>> should go my first attempt to hack this.
>>
>> I'll keep you guys posted on the progress..I think I need a name for this
>> little project.
>>
>> Thanks you
>>
>> Tom
_______________________________________________
use-livecode mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode