What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » AJAX isn't working

AJAX isn't working
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: AJAX isn't working
quote:
Originally posted by The-Phantom
That works perfectly! Huge thanks! [Image: jumpy.gif]
sorry, but what Matti posted should not be done unless you want to slow down Messenger...

--------------

quick note to Matti first:

Matti, shouldn't that be:

// Note the 3rd argument: async = false, thus send() does not return immediately

The whole point of a synchronous call is exactly that send() will not return immediatly; it will wait until the whole thing is retrieved and thus it will slow down, if not lock up, Messenger!

Only when you have an asynchronous call, the send will return immediatly (and hence the reason why he had to make (bad) use of that loop)....

--------------

So, I do very highly recommend using an asynchronous method though! And actually advise against using a synchronous (async=false) method like Matti suggested.

By using a synchronous you will always end up slowing down and even locking up Messenger in one way or the other.

So, the problem you had is not because of the asynchronous call, but because you did not properly used the return function. Do not return (or wait to return) some text in the OnEvent_ChatWndSendMessage itself! That is not the proper way of doing things.

What you should be doing is:

1) in OnEvent_ChatWndSendMessage:
   a) make the asynchronous call and assign another function to the onreadystatechange property
   b) return ""
2) And only inside that other function which got assigned to onreadystatechange (and thus NOT outside this function like you did before with that loop), you do what you want to do.

Also note: in case you want to send some text back to the chat window in response to the outcome of the http call, check if the chat window still exists (highly important), then check if you actually can send some text. After that send the text you want with SendMessage... But all this also requires some additional scripting including keeping track of chat window objects and the contacts within the chats! So you will need to create and maintain an array on the global scope of the script too. And chats with more than one person will make this rather complicated though.

Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
    if (Message.substr(0, 10) === "/ajax-test") {
        Debug.Trace("Retrieving " + Message.substr(11));
        var xhr = new ActiveXObject("Microsoft.XMLHTTP");
        xhr.open("GET", encodeURI(Message.substr(11)), true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    Debug.Trace("html: " + xhr.responseText);
                } else {
                    Debug.Trace("error: " + xhr.status);
                }
            }
        }
        xhr.send();
        return ""
    }
}

Although I suspect that you better assign the XMLHTTP object in the global scope though. Can't be bothered checking on how Plus! handles such stuff/objects when used asynchronously...

---------

Also:
quote:
Originally posted by The-Phantom
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
    if (Message.substr(0, 10) != "/ajax-test") return "";
    // your code for the command /ajax-test here
}


That is very wrong and you should never be doing this. You cripple the proper workings of command handling by that. You should be doing the opposite:
Javascript code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
    if (Message.substr(0, 10) === "/ajax-test") {
        // your code for the command /ajax-test here
        return "";
    }
}

Note that there is no Return outside the IF statement.

This post was edited on 08-29-2010 at 09:00 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-29-2010 08:24 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
AJAX isn't working - by The-Phantom on 08-28-2010 at 01:33 PM
RE: AJAX isn't working - by V@no on 08-29-2010 at 05:31 AM
RE: AJAX isn't working - by The-Phantom on 08-29-2010 at 07:09 AM
RE: AJAX isn't working - by Matti on 08-29-2010 at 07:10 PM
RE: AJAX isn't working - by The-Phantom on 08-29-2010 at 07:57 PM
RE: AJAX isn't working - by CookieRevised on 08-29-2010 at 08:24 PM
RE: AJAX isn't working - by Matti on 08-29-2010 at 08:43 PM
RE: AJAX isn't working - by The-Phantom on 08-30-2010 at 06:48 AM
RE: AJAX isn't working - by CookieRevised on 08-30-2010 at 08:31 AM
RE: RE: AJAX isn't working - by The-Phantom on 08-30-2010 at 08:40 AM
RE: RE: RE: AJAX isn't working - by CookieRevised on 08-30-2010 at 09:01 AM
RE: RE: RE: RE: AJAX isn't working - by The-Phantom on 08-30-2010 at 09:22 AM
RE: AJAX isn't working - by Eljay on 08-30-2010 at 09:41 AM
RE: AJAX isn't working - by CookieRevised on 08-30-2010 at 10:12 AM
RE: AJAX isn't working - by Eljay on 08-30-2010 at 10:35 AM


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