Jump to content

How to read http.response back into the requesting page ?


You are about to reply to a thread that has been inactive for 4725 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I start with a confession.  I am stumped in getting this http.response thing to work as I want it to. It's humiliating to admit but there you go !

I'm new to this so I'll keep things simple or rather - you'll need to keep things simple !  I've used the echo world example in the wiki to send some text from a webpage into my in world prim by tagging the data onto the ? part of the url and delightfully got the expected response from the http.response.  What i'm trying to do is read the response back into the webpage but all I get is a separate page with just the response.

Is it possible to send the response back in the url and read it with javascript location.search ?  I've tried that and can't get it to work.  I'm not familiar with php but if anyone has an example of how to get the response back and pass it into a javascript variable that would make me very happy.

Also - I'm, using a persistent url redirect ( I can't remember the address but it's mentioned in one of the examples) so I think that my confuse issues a little.

Thanks for any help. :


 

Link to comment
Share on other sites

I send data from a javascript on a webpage to an in world prim.  I get whatever data I send back to the same javascript it came from :)

I only mentioned PHP becuase I notice it is mentioned in some of the solutions I've tried but if it's possible to go directly from the prim back to the initial webapge with the javascript in it then that would be even better.

Link to comment
Share on other sites

Sorry - You are right. It is confusing.

I just want to use my in world prim to hold some persistent data for my webpage javascript. ( I know this is the wrong way round for most people but I can do so much more with LSL than server side scripty so I want to use LSL to do the processing for my javascript.

I can submit the data to the prim using method GET in a form or whatever in the javascript

In the prim I use HTTP in - do the processing and send the response.

I would just klike to read the response back into the page that sent the initial data on the end of the url or by using a post method if possible.

 

 

Link to comment
Share on other sites

Ok - I think I understood now. It's more of an Java Script issue than a LSL issue.

I haven't really tried it, but what you do is basically pulling data to a webpage using JS - and that's well possible using e.g. a frame or iFrame and with a frame.location = url command. You put the contents of your response into the body.

Link to comment
Share on other sites

Thank you for all your answers and the suggestion.  I've not used frames before but I find it  difficult to think how frames can be used to 'pull' the response to the window or any part of the document.  Isn't what you are suggesting just setting a property of the frame ?

Surely it's not possible to do that becuase you can't set the property to something that isn't there !  The response isn't an url address is it. It's sent out from the hhtp.response. You can't address that from javascript. That's where I'm starting from becuase that is where the response comes from. Not from another document.

Sorry to sound stupid but can you explain what you mean a little more. How can the frame be set from an http.response ?


 

 

Link to comment
Share on other sites

That won't work.  It's the prim that is initiating the response using http.response becuase that's the way the information is sent back.  It's not possible for the webpage javascript to get it via a url becuase it's not a file waiting to be retrieved and so there isn't a url to load but only an http.response being sent out but correct me if I'm wrong.  In fact - I hope I am becuase It would be really good if this were possible.

Link to comment
Share on other sites

here is what I see, and correct me if I'm wrong...

you have an external page,running some javascript, that requests a page from and inworld http server

you want to pull the information from the response (given by the in world http server) into the page you requested from?

do I have that right?

 

if so, then your choices are, use jQuery or AJAX in your external page to request the inworld data (it will comeback as plain text), or use php and cURL on the external web server to pull that data from the inworld http source, and insert it into your external page before it's served.

 

inworld http servers recieve requests with the http_request event (NOT the llHTTPRequest function) and return their data with the llHTTPResponse function (NOT the http_response event).

inworld http requesters use the opposite function/event pair not used by servers, to request data, and then process what's received.

Link to comment
Share on other sites

Yes - That is precisely what I wish to do and from your reply it sounds like it is possible.

I am receiving the requests with the http_event and sending with the llHTTPresponse function as you mention.  That part is all OK. It's just pulling the response into the page that requested the data that I'm stuck with.

I've never used jQuery or AJAX but I'll look it up.  I think I could use those but are you saying that if I use either of those and it comes back as plain text i wont be able to load it into the page ?

I definately need to load it into the page that sent the initial request and specifically intojavascript variable/s

Is this possible with what you're suggesting ?


Link to comment
Share on other sites

jQuery and AJAX use javascript libraries to add new commands to javascript and extend functionality. you would simmply add another script tag with it's source as the the name of the library file (they're also free and open source, so you just copy it to your external weserver). from there you can use the new command in your normal javascript to request whatever you need.

personally I'd go with jQuery, as there are tons of sites that help with it, so getting information about basic stuff has been asked a million times and is easy to find.

Link to comment
Share on other sites

I'm still having problems with this.    :matte-motes-sour:

My in world prim receives messages just fine and sends a response when it receives a querystring on the end of url that I type into my browser address bar.

I've also noticed that it receives and sends a reply if I send the querystring from a jquery $.get in my outside world script but in that case I can't seem to get a response back into the script. I'm not sure what's wrong with my jquery script.

There are two specific problems.

1.  If in the javascript I tag on the querystring to the url as I do in the browser window with just a \? then the prim receives the query.  However, I can't get it to even receive the query if I put the data in the second parameter of the jquery.

ie; The  { data } part.  I want to do that becuase eventually the data will be a variable that I want to send but when I place it in there the prim doesn't get it.

2. The second problem is actually receiving the response. using the simplest example possible. ie: an alert message of the response in the jquery callback nothing happens.  I've tried everything I can think of to sort this out and it doesn't work and I don't know why but I did read Jquery doesn't work cross domain. Is that so ? If so then how is it possible ?

Here is the Jquery I'm using. 

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Demo</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    <script type="text/javascript">
$(document).ready(function(){
$.get("http://sim9247.agni.lindenlab.com:12046/cap/a2277ce3-d946-681a-77f5-337d732b5f4c/?my-data-I-send-in-the-query-string",function(data){alert("Returned data...." + data);});

 });  // end of ready function


 
    </script>

</head>
<body>
<h2> testing jqueryget </h2>
  </body>
</html>



 

Link to comment
Share on other sites

You should put the code you want to execute in a function and then call this function from an event handler. So much for the syntax aspects. I don't know too much about getting data to SL from java script, but when I fiddled around with it a bit, I remember that I never really managed to pass data to SL - I'm sure you can, I just decided that it's much easier with php and fsocks.

Link to comment
Share on other sites

I have to admit i'm not up on jQuery syntax, so I don't know if that's right or not... but according to this page the format should probably have been...

$.get( '<obscenely long cap address goes here>', {'search string parameter':'search string value'}, function( in_data, in_response ){    alert( 'Response: ' + in_response + '\nData: ' + in_data );}, 'text/plain' );

and if I recall some browsers don't like when you use ;} together, so always add a line feed between them

ETA:
it's not obvious from the linked examples, but $.get probably won't guess the content type, so it should be explicit as shown in my example above... I included the response because it makes troubleshooting easier

Link to comment
Share on other sites

Darkie, Thank you for taking the time to reply.

The code I want to execute IS in a function.  If you look at the example it's in the $(document).ready(function()  and as I mentioned, as long as I place the data I want to pass on to the end of the URL as a query string it works.  It only doesn't work if I place it as the second parameter of the $get jquery.

What doesn't work is receiving the response back into the callback section of the $get even though I know my prim is sending the response.

If this can be done I would be very grateful for any help and even extra grateful for specific example code ! :matte-motes-smile:


 


Link to comment
Share on other sites

no guarantees.... I stopped doing web work long ago, and only fiddle with it now.

honestly PHP and cURL seems a simpler solution, as it could be injected before the page was ever served, and no worries about 'same origin' policies in the browser... if the above fails, that will likely be the reason why. it can be tested for by using the .ajaxError() method before that snippet.

Link to comment
Share on other sites

Well that didn't work so I guess I've reached the end of the line. The more I read the more I'm suspecting that the cross domain circumstances are the issue. It's just not allowed. So I guess I will have to learn php which is annoying becuase I don't think my isp allows php scripts. 

 

 

 

Link to comment
Share on other sites

it might also help if you tell us what you are specifically trying to do.... we might be able to offer alternatives...

for instance, in my own experiments with http-in for LSL I've been hotloading page content by creating and appending a scrept element to the head, and requesting as it's source, a plaintext page from the inworld server... the inworld server spits back the data a text file, which is treated as a script by the page.... on the server side I actually wrap the page content in a javascript variable, and when it loads, the event fires, looks for the variable, and takes it's contents and replaces the page body with them....

it sounds more complex than it really is... the only real trickery is in creating the script element on the fly.... after that any source is treated as javascript that loads normally.

Link to comment
Share on other sites

Are you saying that you can send back a javascript page in the http response ?  I don't understand how you can do this becuase the llHttpresponse doesn't even allow us to send back HTML.  Are you doing this without relying on any other client or server side scripts ?   Could you possibly post an example of what you mean becuase I'm not sure what you mean when you say you wrap the content in a javascript variable.  The only thing I have available for returning is the llhttpresponse.

Link to comment
Share on other sites

While I'm here - i'll just mention something else I noticed  :)

I've read that if you include an   access-control-allowed  header (presumably in the httpresponse) then cross domain http requests and responses are permitted by the browser. 

Unfortunately there's no mention of http headers in the response of the lsl llhttpresponse or if it's the case of placing it in the httprequest how an lsl script could handle it because it's not a permitted header according to the lsl documentation.

If we could do that everything would be solved instantly becuase the block seems to be with the browser and to me that would seem to be the easiest solution to implement.

Link to comment
Share on other sites

scripts are immune to the same origin rule in every browser I know of that support javascript....

A working example can be found here. if you don't use a V2 browser, you may also want to add the "To Go Cup" script linked at the bottom of the page....

for your page, you can simple write your inworld http source to send javascript that will get sent to the browser and execute when it is loaded to the page, by making the inworld page address your script src attribute. just make sure not to include any line breaks inside of strings (change then to be "\n")

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4725 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...