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:
citricsquid
New Member
*

<div style="sexy;100%">

Posts: 13
32 / Male / Flag
Joined: Sep 2008
O.P. The data necessary to complete this operation is not yet available
Sorry for the double topic, I've spent ages trying to figure this out and a search yields no results :(

I'm using this and I've got everything working and modified to my needs; The script and php communicate and it executes perfectly, but as soon as I try to do the following:

JScript code:
return xmlhttp.responseText;


It errors with

quote:
Error: The data necessary to complete this operation is not yet available.
(code: -2147483638)

Now, I presume this means it's not had chance to retrieve the data yet? How do I allow it to?

JScript code:
xmlhttp.send(data);


Has already been called, however it doesn't appear to be able to echo out the received text? Am I doing something ridiculously wrong, or is this a deficiency I'll have to deal with?


EDIT:

Thinking about it, the page will take around 0.02 to process, which is too slow for the script, how can I tell it to wait until the page is loaded? That appears to be the problem.

Oh wait, I have an idea.

While xmlhttp.status != 200 wait, then when it is == 200 execute the function? Seems the only way to do it, then I can run a variable tally whilst the while loop is going and if it goes for too long it timesout?

*thinking out loud*

EDIT:

I got that to work; it doesn't. I got the script to pause for 5 seconds and it still didn't collect the data and the php processes in ~0.02 - So, problem with my script it appears.

This post was edited on 11-15-2008 at 08:06 PM by citricsquid.
11-15-2008 08:02 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: The data necessary to complete this operation is not yet available
You should only use the responseText property when (xmlhttp.readyState == 4) and (xmlhttp.status == 200). Try that and see if it works.
code:
(...)
xmlhttp.onreadystatechange = function () {
   if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         // Data is available now
         DoSomethingUseful(xmlhttp.responseText);
      }
   }
}
xmlhttp.send();

And forget about while loops for doing that. Seriously. Forget it.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-15-2008 08:24 PM
Profile E-Mail PM Web Find Quote Report
citricsquid
New Member
*

<div style="sexy;100%">

Posts: 13
32 / Male / Flag
Joined: Sep 2008
O.P. RE: RE: The data necessary to complete this operation is not yet available
quote:
Originally posted by Matti
You should only use the responseText property when (xmlhttp.readyState == 4) and (xmlhttp.status == 200). Try that and see if it works.
code:
(...)
xmlhttp.onreadystatechange = function () {
   if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
         // Data is available now
         DoSomethingUseful(xmlhttp.responseText);
      }
   }
}
xmlhttp.send();

And forget about while loops for doing that. Seriously. Forget it.

I figured the problem :)
xmlhttp.send(data); doesn't appear to work :|
Well, it sends the data, but it doesn't retrieve what the file outputs.
Debug.Trace(xmlhttp.readyState); shows "1" so the connection's been opened but no data sent, but the data has been sent.

This is mighty confusing.
11-15-2008 08:40 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: The data necessary to complete this operation is not yet available
Now that is very strange! :S

Could you please post your complete code here, preferably in [code]...[/code] tags?
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 09:59 AM
Profile E-Mail PM Web Find Quote Report
citricsquid
New Member
*

<div style="sexy;100%">

Posts: 13
32 / Male / Flag
Joined: Sep 2008
O.P. RE: RE: The data necessary to complete this operation is not yet available
quote:
Originally posted by Matti
Now that is very strange! :S

Could you please post your complete code here, preferably in [code]...[/code] tags?

Sure thing.
Bear in mind it's only basic at the moment and very insecure :) There probably has been a major oversight on my part, the script is being hacked together with guesses of how Jscript works when I don't have the code from that tutorial :P

When I run a message through the script:

code:
Script is starting
Script is now loaded and ready
Function called: OnEvent_ChatWndSendMessage
1


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);
xmlhttp.send(data);
 
xmlhttp.onreadystatechange = function () {
   if (xmlhttp.readyState == 4)
      if (xmlhttp.status == 200) {
         // Data from URL was retrieved successfully
         // Data is saved in the variable xmlhttp.responseText
      } else {
         // The server returned an HTTP code other than 200
   }
}
// end database call
return xmlhttp.responseText;
// else
 
}else{
return Message;
}
 
      Debug.Trace(xmlhttp.readyState);
//  ending of script
}

11-16-2008 11:34 AM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / 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
citricsquid
New Member
*

<div style="sexy;100%">

Posts: 13
32 / Male / Flag
Joined: Sep 2008
O.P. RE: The data necessary to complete this operation is not yet available
Thankyou :D What I had above was copy and pasted together with guessing included, I've never used any of this before so outside of the PHP I was lost :P

Thanks though, much appreciated. Now to complete it :)
11-16-2008 02:03 PM
Profile PM Web Find Quote Report
citricsquid
New Member
*

<div style="sexy;100%">

Posts: 13
32 / Male / Flag
Joined: Sep 2008
O.P. RE: The data necessary to complete this operation is not yet available
Any ideas why it adds a gap to the message?

If I typed "+1" it returns the success message, but like so:

person says:
Success!

Someone else:
What's with the gap?

I've checked the code and I've not got anything there that should cause it, however if I copy and paste it;

quote:
   


You can see that there is a character there, dunno what's causing it though.
11-16-2008 03:03 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: The data necessary to complete this operation is not yet available
It may be your test.php which gives some extra characters?
If I access the test.php on your server, it gives me:
quote:
No user with this email exists
with a tab character and a new line character at the end. Maybe you should check your code to see if there are no blank characters in front or after your <?php ... ?> tags?
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 03:35 PM
Profile E-Mail PM Web Find Quote Report
citricsquid
New Member
*

<div style="sexy;100%">

Posts: 13
32 / Male / Flag
Joined: Sep 2008
O.P. RE: RE: The data necessary to complete this operation is not yet available
quote:
Originally posted by Matti
It may be your test.php which gives some extra characters?
If I access the test.php on your server, it gives me:
quote:
No user with this email exists
with a tab character and a new line character at the end. Maybe you should check your code to see if there are no blank characters in front or after your <?php ... ?> tags?

I've set it up so people have to register, however I'll probably remove that. Thanks though, I had extra characters in my php file, I'm terrible at this coding :P
11-16-2008 03:42 PM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


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