In the lates version of Unity 3, when I include this line in my code I am receiving an error:
BCE0005: Unknown identifier: ‘XMLHttpRequest’.
Any ideas why?
Full method:
function getApi(uri:String){
var xmlHttpRequest= new XMLHttpRequest();
xmlHttpRequest.open("GET",uri, true);
xmlHttpRequest.send(null);
xmlHttpRequest.onreadystatechange = function(){
if(xmlHttpRequest.readyState == 4 xmlHttpRequest.status == 200)
{
Debug.Log(xmlHttpRequest.responseText);
}
};
}
Because it doesn’t exist. Unity doesn’t use ECMAScript (web JavaScript)
Ah. The docs should probably reflect that a bit more clearly and the file extension should probably be something other than js. And JS is an implementation of the ECMA Script standard, fwiw.
Thanks.
I agree - the name is crap. A quick search of this forum and Google shows the amount of confusion it causes. If you go the JS route, think of it more as ActionScript 3 in terms of syntax and semantics (not exact but closer).
XMLHttpRequest is not guaranteed to work across platforms. You should use the WWW class instead.
It’s guaranteed to NOT work on ANY platform because it doesn’t exist in the .NET/Mono runtime. 
Agreed - this is the way to go.