Since you want to modify the sent message, you need to use a synchronous XMLHTTP request as opposed to an asynchronous request. You need to modify the return value of OnEvent_ChatWndSendMessage, so your script has to wait for the result before continuing execution.
This cannot and should not be done with an infinite loop!!! Your loop essentially blocks the entire Messenger thread, including the onreadystatechange callback!
js code:
function OnEvent_ChatWndSendMessage(Wnd, Message)
{
if(Message.substr(0, 10) != "/ajax-test")
return "";
Debug.Trace("Retrieving " + Message.substr(11));
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
// Note the 3rd argument: async = false, thus send() returns immediately
xhr.open("GET", encodeURI(Message.substr(11)), false);
xhr.send();
if(xhr.status === 200) { // HTTP 200 OK
// Success!
Debug.Trace(xhr.responseText);
} else {
// Something went wrong...
Debug.Trace("Error.");
}
// Return empty message
return "";
}
Tip: wrap your code blocks in [code=js]...[/code] tags for beautiful JavaScript syntax highlighting!