Q:

Titanium XHR cannot connect the server

I' trying to let android app using titanium connect the localhost via xhr, here is the code:  
    function e (){
    var xhr = Titanium. Network.createHTTPClient();
    xhr.onload = function()
    {
        alert(xhr.responseText);
     };
    xhr.onerror = function()
    {
        alert("Error");
    };
    xhr.open("GET","http://localhost/test.php");
    xhr.send();}  

I get an error, and this appears in the process trace:  

I/TiHttpClient(  211): (TiHttpClient-1) [16,27717] Sending error
  Connection to http://localhost refused

A:

the Android Emulator has its own network interface, so localhost is the emulator, not your host machine.  You need to use the IP address 10.0.2.2 to access the machine that the emulator is running on.   See http://juristr.com/blog/2009/10/accessing-host-machine-from-your/

