Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Viewer 2 Ajax_in_Shared_Media_Viewer_2  

Ajax_in_Shared_Media_Viewer_2

What it does is to show a web page with a button and field. If you click on the button it shows the latest Unix Timestamp in the field.

The web page is produced via the LSL script. The Javascript function calls the prim HTTP-In URL to return a function with the Timestamp.
This is not the usual way of doing Ajax, as I had some problems using the 'XMLHttpRequest' object approach. I believe it could be a cross-domain issue. This alternative way creates a HTML Script element tag, and references the prim URL for the Source code. The code calls a function back in the main Javascript code to return the data.

I'm sure there could be other uses of Ajax in LSL. But have to be careful of the 1024 character URL limit.

Thanks to Tali Rosca for getting the ball rolling on using Javascript to get around limitations!

Category: Viewer 2
By : Pavcules Superior
Created: 2010-09-02 Edited: 2010-09-02
Worlds: Second Life

the Zip file

Download all files for Ajax_in_Shared_Media_Viewer_2
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Ajax_in_Shared_Media_Viewer_2_1.lsl
1 string url; // Our base http-in url
2
3 show(string html)
4 {
5
6 llOwnerSay(html);
7
8 llSetPrimMediaParams(0, // Side to display the media on.
9 [PRIM_MEDIA_AUTO_PLAY,TRUE, // Show this page immediately
10 PRIM_MEDIA_CURRENT_URL,html, // The url if they hit 'home'
11 PRIM_MEDIA_HOME_URL,html, // The url currently showing
12 PRIM_MEDIA_HEIGHT_PIXELS,512, // Height/width of media texture will be
13 PRIM_MEDIA_WIDTH_PIXELS,512]); // rounded up to nearest power of 2.
14 }
15
16 // This creates a data: url that will render the output of the http-in url
17 // given.
18 string build_url(string url)
19 {
20 return "data:text/html,
21 <html>
22 <head>
23 <script type=\"text/javascript\">
24
25 function makeRequest()
26 {
27 var oScript = document.createElement('script');
28 oScript.src = '" + url + "&sid='+Math.random();
29 document.body.appendChild(oScript);
30 }
31
32 function callback(sText)
33 {
34 document.timeform.data.value = 'Loaded: ' + sText;
35 }
36
37 </script>
38 </head>
39 <body>
40 <input type=\"button\" value=\"Click Me\" onclick=\"makeRequest()\" />
41 <form name=\"timeform\" >
42 Data:<input type=\"text\" name=\"data\"/>
43 </form>
44 </body>
45 </html>";
46 }
47
48
49 default
50 {
52 {
54 }
55
56 http_request(key id, string method, string body)
57 {
58 if(method == URL_REQUEST_GRANTED)
59 {
60 url = body + "/";
61
62 llOwnerSay(url);
63
64 show(build_url(url));
65 }
66 else if(method == "GET")
67 {
68 llOwnerSay("Getting Time");
69 llHTTPResponse(id,200,"callback(\"" + (string)llGetUnixTime() + "\");" );
70 }
71 }
72 }

Back to the Best Free Tools in Second Life and OpenSim.