Jump to content

Javascript XMLHttpRequest and LSL llHTTPResponse


Mokomoko Bayn
 Share

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

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

Recommended Posts

Hey guys, I'm using this Javascript

var xmlHttp = null;
try {
    // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
    xmlHttp = new XMLHttpRequest();
} catch(e) {
    try {
        // MS Internet Explorer (ab v6)
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        try {
            // MS Internet Explorer (ab v5)
            xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            xmlHttp  = null;
        }
    }
}
if (xmlHttp) {
    xmlHttp.open('POST', 'URL OF MY PRIM', true);
    xmlHttp.send('My Data');
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            alert(xmlHttp.responseText);
        }
	
    };
}

 My LSL Script looks like this:

 

key url_request;
 
default
{
    state_entry()
    {
        url_request = llRequestURL();
    }
    http_request(key id, string method, string body)
    {
        if (url_request == id)
        {
            url_request = "";
            if (method == URL_REQUEST_GRANTED)
            {
                llOwnerSay("URL: " + body);
            }
            else if (method == URL_REQUEST_DENIED)
            {
                llOwnerSay("Something went wrong, no url. " + body);
            }
        }
        else
        {
            llHTTPResponse(id, 200, "I received your data!");
        }
    }
}

 The data is received by my inworld object but the response is empty in my Javascript alert function.
Any ideas?

 

greetings, Mokomoko Bayn

 

P.S.: Sorry for my bad english but I'm from germany ;)

 

Link to comment
Share on other sites

There is an error in your LSL - you return llHTTPResponse on url_request != id. Closed brackets too early:

    http_request(key id, string method, string body)    {        if (url_request == id)        {            url_request = "";            if (method == URL_REQUEST_GRANTED)            {                llOwnerSay("URL: " + body);            }            else if (method == URL_REQUEST_DENIED)            {                llOwnerSay("Something went wrong, no url. " + body);            }            else            {                llHTTPResponse(id, 200, "I received your data!");            }        }    }
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4447 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...