What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » The data necessary to complete this operation is not yet available

The data necessary to complete this operation is not yet available
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: The data necessary to complete this operation is not yet available
Okay, I now see where your problem is.

It is not possible to replace your sent message with a response text retrieved through an asynchronous XMLHTTP request. This is because if you return something in the onreadystatechange event, it'll be returned in the onreadystatechange function, not in the OnEvent_ChatWndSendMessage!

Therefore, there are 2 ways to solve this:
  • Make the call synchronous by doing:
    jscript code:
    xmlhttp.async = false;
    after "var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP')". This way, you can drop the onreadystatechange event and retrieve the response text immediately after you call xmlhttp.send(). However, this may lag your Messenger for a small period of time and is therefore not recommended.
  • Keep your asynchronous call by returning an empty string and use ChatWnd.SendMessage in the ready state event function.
More shocking thing I noticed: you try to access xmlhttp.responseText outside your onreadystatechange function! This is why you get the error: basically, you try to access xmlhttp.responseText immediately after defining the event. It's not because you place it after the function definition that it'll only be executed after the function has been executed, no, that's not how asynchronous calls work. Look at the code in the thread and in my last post: the DoSomethingUseful is inside the if-block in the function!

I think I can only help you by fixing this code myself for you... so here we go:
jscript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
    for(var e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()){
        rEmail = (e.item().Email);
    }
    // return Email;
    // ^ use to echo contacts email address
    // return Messenger.MyName;
    // ^ use to echo current users name

    if(Message.substr(0, 2) === "+1") {
        var name = Messenger.MyName;
        var gEmail = Messenger.MyEmail;
        var rMessage = (name + ' has rewarded you with a +1!');

        // Database call
        var url = "http://plusone.samryan.co.uk/test.php";
        var data = ('rEmail= ' + rEmail + '&gEmail=' + gEmail);

        Interop.Call("wininet.dll", "DeleteUrlCacheEntryW", url);
        var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.open("GET", url, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", data.length);

        // Declare a ready state change event
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    // Data from URL was retrieved successfully
                    // Now we can send the response text
                    ChatWnd.SendMessage(xmlhttp.responseText);
                    // Any other code for when the request was succesful
                    // should go here
                } else {
                    // The server returned an HTTP code other than 200
                }
            }
        };
        // After we declared a ready state change event,
        // we can start the request. It won't get started
        // any earlier than this!
        xmlhttp.send(data);
        // The script won't wait for the request to finish.
        // Therefore we'll return an empty string so the
        // declared event can send a message later.
        return "";
    }
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-16-2008 01:34 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
The data necessary to complete this operation is not yet available - by citricsquid on 11-15-2008 at 08:02 PM
RE: The data necessary to complete this operation is not yet available - by Matti on 11-15-2008 at 08:24 PM
RE: RE: The data necessary to complete this operation is not yet available - by citricsquid on 11-15-2008 at 08:40 PM
RE: The data necessary to complete this operation is not yet available - by Matti on 11-16-2008 at 09:59 AM
RE: RE: The data necessary to complete this operation is not yet available - by citricsquid on 11-16-2008 at 11:34 AM
RE: The data necessary to complete this operation is not yet available - by Matti on 11-16-2008 at 01:34 PM
RE: The data necessary to complete this operation is not yet available - by citricsquid on 11-16-2008 at 02:03 PM
RE: The data necessary to complete this operation is not yet available - by citricsquid on 11-16-2008 at 03:03 PM
RE: The data necessary to complete this operation is not yet available - by Matti on 11-16-2008 at 03:35 PM
RE: RE: The data necessary to complete this operation is not yet available - by citricsquid on 11-16-2008 at 03:42 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On