1

我知道这个问题被问了好几次,我指的是所有这些帖子,即使在那之后也无法解决我的问题。我为客户端服务器通信创建了一个 html 页面。这是代码

<!DOCTYPE html>
<html>
    <head>
        <title>Sandbox</title>

        <script type="text/javascript">

            function log (text) {
                document.getElementById("contents").innerHTML = document.getElementById("contents").innerHTML + "<br />" + text;
            }

            function ready() {
                log("Ready.");
                var xmlhttp = new XMLHttpRequest();

                xmlhttp.onreadystatechange = function () {
                    log("State: " + xmlhttp.readyState + ", Status: " + xmlhttp.status
+ ", Statustext: " + xmlhttp.responseText);
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        log("CSV Content:");
                        log(xmlhttp.responseText);
                    }
                };

                log("Open.");
                xmlhttp.open("GET", "http://10.5.13.142/iptvservice.xml", false);
                log("Send.");
                xmlhttp.send(null);
                log("Sent.");
                window.removeEventListener('DOMContentLoaded', ready, false);
            }

            window.addEventListener('DOMContentLoaded', ready, false);
        </script>

    </head>
    <body>
        <div id="contents">Loading.</div>
    </body>
</html>

服务器是 Apache 服务器。我在安装服务器的同一台机器上运行此页面。在 Mozilla 状态码为 0 并且在加载时挂起。我没有得到什么问题。我已经读到如果你在同一个域上,你不需要在 manifest.json 上设置权限。那么我哪里出错了。请帮忙。

编辑:实际上我的要求是使用 phonegap 在 android 上运行此代码。所以我想使用java脚本。所以任何人都可以建议使用 xmlhttprequest 如何创建客户端服务器连接。

4

1 回答 1

0

sorry, but just now i got this link

XMLHttpRequest Fails On Same Domain

but in my case Apache server giving xml page. So where i should put my script.and this is just for testing purpose i am using same machine, but after that i need to run same page on different machine. Then what would be the solution. sorry i am asking very simple question, but required little help.

Edit: just for information. I did change according to the link

http://www.skill-guru.com/blog/2011/02/04/adding-access-control-allow-origin-to-server-for-cross-domain-scripting/

and then ran on google chrome, it worked, but it still not working on firefox. Anyways, atleast my code and server installation is proper.

于 2013-01-15T06:59:31.113 回答