weixin_33696106 2012-07-11 21:06 采纳率: 0%
浏览 40

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!

  • 写回答

2条回答 默认 最新

  • weixin_33736832 2012-07-11 21:10
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog