AJAX连接到本地主机?

I am designing javascript which can call php on a server (currently my own local computer)

Eventually, I will be using phonegap to interpret the javascript and display the results...

My problem seems to be connecting to the actual server.

Here's my javascript:

  <!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function loadXMLDoc() {
    var xmlhttp;
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("POST", "http://127.0.0.1/myfiles/WorkingVersionVQuickLook.php", true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.send("ipaddress=208.74.76.5");
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
</body>
</html>

It works when instead of the localhost followed by the location, I reference just WorkingVersionVQuicklook.php like this:

 xmlhttp.open("POST","WorkingVersionVQuickLook.php",true)

But once I add the exact location on the localhost it does not.

When I export to my emulator for Android, even the version that does work will not work on the emulator, which led me to the idea that I should specify its on the local machine. But because it does not even work when I do not run it via browser, it will not work on the emulator.

Please help me create a successfully mapped out connection so it will work for a browser, and then hopefully for my android!

Try using /myfiles/WorkingVersionVQuickLook.php and not http://127.0.0.1/myfiles/WorkingVersionVQuickLook.php. Connecting to different hosts using XHR can get tricky.

Potential solution:

First, I think you're probably missing the port number in the absolute URL. Second, you need to use the IP-address used to connect to your computer from other computers on your network. This is because the emulator runs as its own virtualized machine, so using localhost or a relative URL will cause the request to be sent to the specified path on the emulator, not to the path in your main OS's file system.

(Edited to more directly answer the question)