Add some
Debug.Trace() lines to your script and you'll quickly find out some issues with it. Eg: place a
Debug.Trace("hello") line as the first line in your stateChanged() function to actually see if it is called or not (you'll see it actually IS called)... Do the same for each nested structure and each used variable to pin down where the issues are...
Anyways, for starters you have the wrong URL in your script. The URL in your script is the graphical list with all the bells and whistles, not the plain bare list you've shown in your top post in this thread.
Second, the method/property
getElementsByTagName("body")[0].innerHTML doesn't work on the
ResponseText property of the XMLHTTP object. The
getElementsByTagName method is part of the XMLDOM object and thus you need to define that first, something like:
code:
var XMLDOM = new ActiveXObject("Microsoft.XMLDOM");
XMLDOM.loadXML(xmlhttp.ResponseText);
var userStats = XMLDOM.getElementsByTagName("body")[0].innerHTML;
But you don't need that at all, since the website (with the proper URL as listed in your first post, not the URL in the script) will already return only the plain bare list as-is.
So all you need to correct is:
code:
searchURL = "http://hiscore.runescape.com/hiscorepersonal.ws?user1=" + searchName;
.....
var userStats = xmlhttp.ResponseText.getElementsByTagName("body")[0].innerHTML;
to:
code:
searchURL = "http://hiscore.runescape.com/index_lite.ws?player=" + searchName;
.....
var userStats = xmlhttp.ResponseText;
IMPORTANT EDIT:
Oh... and the
stateChanged function should return true or false, not a string!
And since this http request is done assyncroniously, you must not do
code:
ChatWnd.SendMessage(searchStats(Username));
Not only will
searchStats return nothing (you don't have any return statement there), you also don't know if it was succesfully or not.
So you must pass the contact's email to this function instead. This because you must re-open the chat window, check if you can send a string, and then actually send the string if it was succesfully.
The reason for that is because it is assyncroniously and that means the chat window can already be closed by the time the http request returns anything....