The data necessary to complete this operation is not yet available - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: The data necessary to complete this operation is not yet available (/showthread.php?tid=87283)
The data necessary to complete this operation is not yet available by citricsquid on 11-15-2008 at 08:02 PM
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.
RE: The data necessary to complete this operation is not yet available by Matti on 11-15-2008 at 08:24 PM
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.
RE: RE: The data necessary to complete this operation is not yet available by citricsquid on 11-15-2008 at 08:40 PM
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.
RE: The data necessary to complete this operation is not yet available by Matti on 11-16-2008 at 09:59 AM
Now that is very strange!
Could you please post your complete code here, preferably in [code]...[/code] tags?
RE: RE: The data necessary to complete this operation is not yet available by citricsquid on 11-16-2008 at 11:34 AM
quote: Originally posted by Matti
Now that is very strange!
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
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
}
RE: The data necessary to complete this operation is not yet available by Matti on 11-16-2008 at 01:34 PM
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 "";
}
}
RE: The data necessary to complete this operation is not yet available by citricsquid on 11-16-2008 at 02:03 PM
Thankyou 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
Thanks though, much appreciated. Now to complete it
RE: The data necessary to complete this operation is not yet available by citricsquid on 11-16-2008 at 03:03 PM
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.
RE: The data necessary to complete this operation is not yet available by Matti on 11-16-2008 at 03:35 PM
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?
RE: RE: The data necessary to complete this operation is not yet available by citricsquid on 11-16-2008 at 03:42 PM
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
|