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_cross_domain  

Ajax_in_Shared_Media_cross_domain

Although the 'XMLHttpRequest' Javascript function does not work across different domains, the following LSL Script below gets around this problem!
By using Javascript and HTTP-In, the Javascript calls the prim HTTP-In URL. The LSL script (http_request event) then calls to another website to return data from it. When the website returns the data, the "http_response" event it sends a page response back with the data via the HTTP-In method. The response contains the Javascript function to be called with the data to be shown in the webpage.

The script below obtains the latest Moon information. If you press the Click Me button every one minute, the information will be updated.

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_cross_domain
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Ajax_in_Shared_Media_cross_domain_f_1.lsl
1 string g_strURL;
2 key g_keyResponseRequestID;
3 key g_keyRequestID;
4
5 show(string html)
6 {
7
8 llOwnerSay(html);
9
10 llSetPrimMediaParams(0, // Side to display the media on.
11 [PRIM_MEDIA_AUTO_PLAY,TRUE, // Show this page immediately
12 PRIM_MEDIA_CURRENT_URL,html, // The url if they hit 'home'
13 PRIM_MEDIA_HOME_URL,html, // The url currently showing
14 PRIM_MEDIA_HEIGHT_PIXELS,512, // Height/width of media texture will be
15 PRIM_MEDIA_WIDTH_PIXELS,512]); // rounded up to nearest power of 2.
16 }
17
18 // This creates a data: url that will render the output of the http-in url
19 // given.
20 string build_url(string url)
21 {
22 return "data:text/html,
23 <html>
24 <head>
25 <script type=\"text/javascript\">
26
27 function makeRequest()
28 {
29 var oScript = document.createElement('script');
30 oScript.src = '" + url + "?sid='+Math.random();
31 document.body.appendChild(oScript);
32 }
33
34 function callback(sText)
35 {
36 document.getElementById('data').innerHTML = sText;
37 }
38
39 </script>
40 </head>
41 <body>
42 <input type=\"button\" value=\"Click Me\" onclick=\"makeRequest()\" />
43 <br /><br />
44 <div id=\"data\">Press the 'Click Me' button to get current moon info!</div>
45 </body>
46 </html>";
47 }
48
49
50
51 default
52 {
54 {
56 }
57
58 http_request(key id, string method, string body)
59 {
60 if(method == URL_REQUEST_GRANTED)
61 {
62 g_strURL = body + "/";
63
64 llOwnerSay(g_strURL);
65
66 show(build_url(g_strURL));
67 }
68 else if(method == "GET")
69 {
70 // Store the Request ID.
71 g_keyResponseRequestID = id;
72
73 // Call the website to get data.
74 llOwnerSay("Getting data from website..." + (string)g_keyResponseRequestID);
75 g_keyRequestID = llHTTPRequest("http://pkpounceworks.com/pkp/scripts/moon/moontest.php",[],"");
76
77 }
78 }
79
80 http_response(key request_id, integer status, list metadata, string body)
81 {
82 if(g_keyRequestID == request_id)
83 {
84 // Respond the website data back.
85 llHTTPResponse(g_keyResponseRequestID,200,"callback(\"" + body + "\");" );
86 }
87 }
88
89
90 }

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